bool TrainProcessor::fillSamples(const std::string &inputName, cv::Mat &samples, cv::Mat &categories) { FILE* f = fopen(inputName.c_str(), "rt"); if (f == 0) { return false; } cv::Mat image, gray, resized, resizedFloat; std::vector<cv::Mat> imagesVector; std::vector<char> categoriesVector; char buf[1000]; while (fgets(buf, 1000, f)) { int len = (int) strlen(buf); while (len > 0 && isspace(buf[len-1])) { len--; } buf[len] = '\0'; std::string imageName(buf); char cat = category(imageName); std::cout << "file " << imageName.c_str() << std::endl; if (cat == '\0') { std::cout << "WARNING: no category detected" << std::endl; std::cout << std::endl; continue; } else if (myClassesList.find(cat) == std::string::npos) { std::cout << "WARNING: unknown category detected" << std::endl; std::cout << std::endl; continue; } image = cv::imread(imageName, 1); if (!image.empty()) { cv::cvtColor(image, gray, CV_BGR2GRAY); cv::resize(gray, resized, myFaceSize, 0, 0, cv::INTER_LINEAR); cv::equalizeHist(resized, resized); resized.convertTo(resizedFloat, CV_32FC1, 1.0 / 255); imagesVector.push_back(cv::Mat()); cv::Mat &vec = imagesVector.back(); resizedFloat.reshape(0, 1).copyTo(vec); categoriesVector.push_back(cat); } else { std::cout << "WARNING: unable to read file" << std::endl; std::cout << std::endl; } } fclose(f); samples.create(imagesVector.size(), myFaceSize.width * myFaceSize.height, CV_32FC1); categories.create(imagesVector.size(), 1, CV_8UC1); for (size_t i = 0; i < imagesVector.size(); ++i) { cv::Mat rowi = samples.row(i); imagesVector[i].copyTo(rowi); categories.at<unsigned char>(i, 0) = categoriesVector.at(i); } return true; }
Home::Home(QWidget *parent) : QWidget(parent), ui(new Ui::Home), b_optionDialogOpened(false), m_optionsDialog(NULL), b_serverWidgetOpened(false), m_serverWidget(NULL) { ui->setupUi(this); QString url("http://www.runicorbs.net/ingame.php?syslang=" + QLocale::system().name() + "&version=" + QString::fromUtf8(QUrl::toPercentEncoding(TRO_VERSION))); ui->newsWebView->setUrl(url); QString imageName(qApp->applicationDirPath() + "/gfx/logo.png"); if(QFile(imageName).exists()) { ui->titleLabel->setPixmap(QPixmap(imageName)); } else { ui->titleLabel->setText("The Runic Orbs"); } connect(ui->soloButton, SIGNAL(clicked()), this, SLOT(soloGameLaunch())); connect(ui->multiButton, SIGNAL(clicked()), this, SLOT(openConnectDialog())); connect(ui->serverButton, SIGNAL(clicked()), this, SLOT(openServerWidget())); connect(ui->optionsButton, SIGNAL(clicked()), this, SLOT(openOptions())); connect(ui->quitButton, SIGNAL(clicked()), this, SLOT(close())); ui->versionLabel->setText(tr("version %1").arg(TRO_VERSION)); // Center the window on the screen QDesktopWidget* desktop = QApplication::desktop(); move( (desktop->width() - width()) / 2 , (desktop->height() - height()) / 2 - 50 ); }
PassRefPtr<Image> Image::loadPlatformResource(const char* name) { CString fileName; if (!strcmp("missingImage", name)) fileName = getThemeIconFileName(GTK_STOCK_MISSING_IMAGE, 16); if (fileName.isNull()) { GUniquePtr<gchar> imageName(g_strdup_printf("%s.png", name)); GUniquePtr<gchar> glibFileName(getPathToImageResource(imageName.get())); fileName = glibFileName.get(); } return loadImageFromFile(fileName); }
PassRefPtr<Image> Image::loadPlatformResource(const char* name) { CString fileName; if (!strcmp("missingImage", name)) fileName = getThemeIconFileName(GTK_STOCK_MISSING_IMAGE, 16); if (fileName.isNull()) { GOwnPtr<gchar> imageName(g_strdup_printf("%s.png", name)); GOwnPtr<gchar> glibFileName(g_build_filename(getWebKitDataDirectory(), "webkitgtk-"WEBKITGTK_API_VERSION_STRING, "images", imageName.get(), NULL)); fileName = glibFileName.get(); } return loadImageFromFile(fileName); }
void FlagComponent::saveToFile() { /* TODO: This is a really bad way of storing things. Adding one flag shouldn't involve writing a new file/table every time. Needs fixing. */ KStarsData::Instance()->userdb()->EraseAllFlags(); for ( int i=0; i < size(); ++i ) { KStarsData::Instance()->userdb()->AddFlag(QString::number( pointList().at( i )->ra0().Degrees() ), QString::number( pointList().at( i )->dec0().Degrees() ), epoch ( i ), imageName( i ).replace( ' ', '_' ), label( i ), labelColor( i ).name()); } }
int basic_test(){ string imageName("test_vid/nyc_test.jpg"); Mat image; image = imread(imageName.c_str(), IMREAD_COLOR); // Read the file if (!image.data) // Check for invalid input { cout << "Could not open or find the image" << std::endl; return -1; } resize(image, image, Size(image.cols / 4, image.rows / 4)); namedWindow("Display window", CV_WINDOW_AUTOSIZE); // Create a window for display. imshow("Display window", image); // Show our image inside it. waitKey(0); // Wait for a keystroke in the window return 0; }
IntlData *LoadInternationalData( const char *file_prefix ) { IntlData *data; int fh; res_language_enumeration language; unsigned len; char *drive; char *dir; char cmd_name[_MAX_PATH]; char split_buff[_MAX_PATH2]; char base[16]; language = _WResLanguage(); if( language == RLE_ENGLISH ) { return( NULL ); } if( imageName( cmd_name ) == NULL ) { return( NULL ); } _splitpath2( cmd_name, split_buff, &drive, &dir, NULL, NULL ); len = strlen( file_prefix ); if( len > 6 ) { len = 6; } memcpy( base, file_prefix, len ); base[len++] = '0'; base[len++] = '0' + language; base[len] = '\0'; _makepath( cmd_name, drive, dir, base, "." LOCALE_DATA_EXT ); fh = sopen3( cmd_name, O_RDONLY | O_BINARY, SH_DENYWR ); if( fh == -1 ) { return( NULL ); } data = getData( fh ); if( data != NULL ) { if( data->usage_text == NULL || data->errors_text == NULL ) { FreeInternationalData( data ); data = NULL; } } close( fh ); return( data ); }
QList<ProcData> winProcessList() { QList<ProcData> rc; PROCESSENTRY32 pe; pe.dwSize = sizeof(PROCESSENTRY32); HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (snapshot == INVALID_HANDLE_VALUE) return rc; for (bool hasNext = Process32First(snapshot, &pe); hasNext; hasNext = Process32Next(snapshot, &pe)) { ProcData procData; procData.ppid = QString::number(pe.th32ProcessID); procData.name = QString::fromUtf16(reinterpret_cast<ushort*>(pe.szExeFile)); procData.image = imageName(pe.th32ProcessID); rc.push_back(procData); } CloseHandle(snapshot); return rc; }
int main() { /* const char *macs[4] = { "00-21-29-96-31-e7", "00-25-9c-57-de-a2", "00-21-91-51-58-6d", "00-17-9a-02-4e-05" }; */ std::string file("../pics/IMG_0024.JPG.log"); std::string imageName("IMG_0024.JPG"); LogFileResult result = parseLogFile(file, imageName); std::cout << "result found " << result.image_found << " at " << result.image_time << std::endl; std::cout << result.aps.size() << " aps." << std::endl; for (int i = 0; i < result.aps.size(); i++) { AccessPoint point = result.aps[i]; std::cout << "ap " << point.mac_address << " with signal " << point.signal << " at " << point.time << std::endl; } GeoLocateResult gresult = geolocate_locate(result.aps); std::cout << "lat " << gresult.lat << " lon " << gresult.lon << " accuracy " << gresult.accuracy << " succeeded " << gresult.success << std::endl; std::string imgFile("photo.jpg"); dumpAllExif(imgFile); ExifGPS gps = readGPS(imgFile); std::cout << "gps lat " << gps.lat << " gps lon " << gps.lon << std::endl; std::string tmpFile("test.jpg"); writeGPS(tmpFile, gps); dumpAllExif(tmpFile); return 0; }
int find_contour(){ int thresh = 100; RNG rng(12345); string imageName("test_vid/test_1.jpg"); Mat src; src = imread(imageName.c_str(), IMREAD_GRAYSCALE); if (!src.data){ cout << "Could not open or find the image" << std::endl; return -1; } namedWindow("Source", CV_WINDOW_AUTOSIZE); imshow("Source", src); Mat canny_output; vector<vector<Point> > contours; vector<Vec4i> hierarchy; /// Detect edges using canny Canny(src, canny_output, thresh, thresh * 2, 3); /// Find contours //findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); Mat drawing = Mat::zeros(canny_output.size(), CV_8UC3); for (int i = 0; i< contours.size(); i++) { Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)); drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point()); } /// Show in a window namedWindow("Contours", CV_WINDOW_AUTOSIZE); imshow("Contours", drawing); waitKey(0); return(0); }
int find_hsv(){ int H_MIN = 0; int H_MAX = 256; int S_MIN = 0; int S_MAX = 256; int V_MIN = 0; int V_MAX = 256; string imageName("test_vid/test_1.jpg"); Mat image; image = imread(imageName.c_str(), IMREAD_COLOR); // Read the file if (!image.data) // Check for invalid input { cout << "Could not open or find the image" << std::endl; return -1; } Mat HSV; Mat threshold; cvtColor(image, HSV, COLOR_BGR2HSV); //filter HSV image between values and store filtered image to //threshold matrix inRange(HSV, Scalar(H_MIN, S_MIN, V_MIN), Scalar(H_MAX, S_MAX, V_MAX), threshold); const string windowName = "Original Image"; const string windowName1 = "HSV Image"; const string windowName2 = "Thresholded Image"; imshow(windowName2, threshold); imshow(windowName, image); imshow(windowName1, HSV); waitKey(0); // Wait for a keystroke in the window return 0; }
void BreakConditionConfigWindow::MessageReceived(BMessage* message) { switch (message->what) { case MSG_STOP_ON_THROWN_EXCEPTION_CHANGED: { _UpdateThrownBreakpoints(fExceptionThrown->Value() == B_CONTROL_ON); break; } case MSG_STOP_ON_CAUGHT_EXCEPTION_CHANGED: { break; } case MSG_SET_STOP_FOR_ALL_IMAGES: { fListener->SetStopOnImageLoadRequested( fStopOnImageLoad->Value() == B_CONTROL_ON, false); break; } case MSG_SET_STOP_FOR_CUSTOM_IMAGES: { fListener->SetStopOnImageLoadRequested( fStopOnImageLoad->Value() == B_CONTROL_ON, true); break; } case MSG_IMAGE_NAME_SELECTION_CHANGED: { if (!fUseCustomImages) break; fRemoveImageNameButton->SetEnabled( fStopImageNames->CurrentSelection() >= 0); break; } case MSG_IMAGE_NAME_INPUT_CHANGED: { BString imageName(fStopImageNameInput->Text()); imageName.Trim(); fAddImageNameButton->SetEnabled(!imageName.IsEmpty()); break; } case MSG_STOP_ON_IMAGE_LOAD: { fListener->SetStopOnImageLoadRequested( fStopOnImageLoad->Value() == B_CONTROL_ON, fUseCustomImages); break; } case MSG_STOP_IMAGE_SETTINGS_CHANGED: { _UpdateStopImageState(); break; } case MSG_ADD_IMAGE_NAME: { BString imageName(fStopImageNameInput->Text()); imageName.Trim(); AutoLocker< ::Team> teamLocker(fTeam); if (fTeam->StopImageNames().HasString(imageName)) break; fStopImageNameInput->SetText(""); fListener->AddStopImageNameRequested(imageName.String()); break; } case MSG_STOP_IMAGE_NAME_ADDED: { const char* imageName; if (message->FindString("name", &imageName) != B_OK) break; BStringItem* item = new(std::nothrow) BStringItem(imageName); if (item == NULL) break; ObjectDeleter<BStringItem> itemDeleter(item); if (!fStopImageNames->AddItem(item)) { break; } itemDeleter.Detach(); fStopImageNames->SortItems(SortStringItems); break; } case MSG_REMOVE_IMAGE_NAME: { BStringItem* item; int32 selectedIndex; AutoLocker< ::Team> teamLocker(fTeam); int32 i = 0; while ((selectedIndex = fStopImageNames->CurrentSelection(i++)) >= 0) { item = (BStringItem*)fStopImageNames->ItemAt(selectedIndex); fListener->RemoveStopImageNameRequested(item->Text()); } break; } case MSG_STOP_IMAGE_NAME_REMOVED: { const char* imageName; if (message->FindString("name", &imageName) != B_OK) break; for (int32 i = 0; i < fStopImageNames->CountItems(); i++) { BStringItem* item = (BStringItem*)fStopImageNames->ItemAt(i); if (strcmp(item->Text(), imageName) == 0) { fStopImageNames->RemoveItem(i); delete item; } } break; } default: BWindow::MessageReceived(message); break; } }