int main(int argc, char* argv[]) { int c; int dirnum = -1; uint32 diroff = 0; oerror = TIFFSetErrorHandler(NULL); owarning = TIFFSetWarningHandler(NULL); while ((c = getopt(argc, argv, "d:o:p:eflmsvw?")) != -1) switch (c) { case 'd': dirnum = atoi(optarg); break; case 'e': oerror = TIFFSetErrorHandler(oerror); break; case 'l': order0 = FILLORDER_LSB2MSB; break; case 'm': order0 = FILLORDER_MSB2LSB; break; case 'o': diroff = strtoul(optarg, NULL, 0); break; case 'p': photo0 = photoArg(optarg); break; case 's': stoponerr = 1; break; case 'w': owarning = TIFFSetWarningHandler(owarning); break; case 'v': verbose = 1; break; case '?': usage(); /*NOTREACHED*/ } filenum = argc - optind; if ( filenum < 1) usage(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); /* * Get the screen size */ xmax = glutGet(GLUT_SCREEN_WIDTH); ymax = glutGet(GLUT_SCREEN_HEIGHT); /* * Use 90% of the screen size */ xmax = xmax - xmax / 10.0; ymax = ymax - ymax / 10.0; filelist = (char **) _TIFFmalloc(filenum * sizeof(char*)); if (!filelist) { TIFFError(argv[0], "Can not allocate space for the file list."); return 1; } _TIFFmemcpy(filelist, argv + optind, filenum * sizeof(char*)); fileindex = -1; if (nextImage() < 0) { _TIFFfree(filelist); return 2; } /* * Set initial directory if user-specified * file was opened successfully. */ if (dirnum != -1 && !TIFFSetDirectory(tif, dirnum)) TIFFError(argv[0], "Error, seeking to directory %d", dirnum); if (diroff != 0 && !TIFFSetSubDirectory(tif, diroff)) TIFFError(argv[0], "Error, setting subdirectory at %#x", diroff); order = order0; photo = photo0; if (initImage() < 0){ _TIFFfree(filelist); return 3; } /* * Create a new window or reconfigure an existing * one to suit the image to be displayed. */ glutInitWindowSize(width, height); snprintf(title, TITLE_LENGTH - 1, "%s [%u]", filelist[fileindex], (unsigned int) TIFFCurrentDirectory(tif)); glutCreateWindow(title); glutDisplayFunc(raster_draw); glutReshapeFunc(raster_reshape); glutKeyboardFunc(raster_keys); glutSpecialFunc(raster_special); glutMainLoop(); cleanup_and_exit(); return 0; }
/*! \fn ViewerWidget::keyPressEvent(QKeyEvent *k) Handle all keyboard events. All events which are not handled trigger a help window. */ void ViewerWidget::keyPressEvent(QKeyEvent* k) { QPoint middlepoint; switch (k->key()) { // next image case Qt::Key_N: case Qt::Key_Right: case Qt::Key_Down: case Qt::Key_PageDown: case Qt::Key_Space: nextImage(); break; // previous image case Qt::Key_P: case Qt::Key_Left: case Qt::Key_Up: case Qt::Key_PageUp: prevImage(); break; // rotate image case Qt::Key_R: texture->rotate(); downloadTex(texture); updateGL(); break; // terminate image viewer case Qt::Key_Escape: // clean up: where does this have to be done? close(); break; // full screen case Qt::Key_F: // according to QT documentation, showFullScreen() has some // serious issues on window managers that do not follow modern // post-ICCCM specifications if (isFullScreen()) { texture->reset(); showNormal(); } else { texture->reset(); showFullScreen(); } break; // reset size and redraw case Qt::Key_Z: texture->reset(); updateGL(); break; // toggle permanent between "show next image" and "zoom" on mousewheel change case Qt::Key_C: if (wheelAction==zoomImage) wheelAction=changeImage; else wheelAction=zoomImage; break; // zoom in case Qt::Key_Plus: middlepoint = QPoint(width()/2,height()/2); if (texture->setSize( zoomsize )) downloadTex(texture); //load full resolution image zoom(-1, middlepoint, zoomfactor_keyboard); break; // zoom out case Qt::Key_Minus: middlepoint = QPoint(width()/2,height()/2); if (texture->setSize( zoomsize )) downloadTex(texture); //load full resolution image zoom(1, middlepoint, zoomfactor_keyboard); break; // zoom to original size case Qt::Key_O: texture->zoomToOriginal(); updateGL(); break; // toggle temorarily between "show next image" and "zoom" on mousewheel change case Qt::Key_Control: if (wheelAction == zoomImage) { //scrollwheel changes to the next image wheelAction = changeImage; } else { //scrollwheel does zoom wheelAction = zoomImage; setCursor (zoomCursor); timerMouseMove.stop(); } break; //do noting, don't trigger the help dialog case Qt::Key_Shift: break; //key is not bound to any action, therefore show help dialog to enlighten the user default: QPointer<QDialog> d = new QDialog(this); Ui::HelpDialog hd; hd.setupUi(d); d->exec(); delete d; break; } }
void tricks::vision::Camera::setup(int width, int height, string testVideoFile, string imagesFolder) { saveNextFrame = false; #ifndef TEST_WITH_VIDEO #ifdef _WIN32 -- firewire.setDeviceID(0); sdk = new FlyCaptureGrabber; sdk->listDevices(); #else Libdc1394Grabber *sdk = new Libdc1394Grabber; sdk->listDevices(); sdk->setDiscardFrames(true); sdk->set1394bMode(false); char path[512]; getcwd(path, 512); printf("Working directory: %s\n", ofToDataPath("", true).c_str()); #endif ofxIIDCSettings *settings = new ofxIIDCSettings; settings->setXMLFilename("mySettingsFile.xml"); firewire.setVerbose(true); #ifdef CAM_GREYSCALE bool result = firewire.initGrabber( width, height, VID_FORMAT_GREYSCALE, VID_FORMAT_GREYSCALE, 30, true, sdk, settings ); #else bool result = firewire.initGrabber( width, height, VID_FORMAT_YUV422, VID_FORMAT_RGB, 30, true, sdk, settings ); #endif canDoFirewire = result; #ifdef _WIN32 // setup the gui printf("Setted up gui\n"); myGui.setup(); myGui.addListener(this); int numProps = sdk->getNumProperties(); for(int i = 0; i < numProps; i++) { string name; float value = 0; float min = 0; float max = 0; sdk->getPropertyInfo(i, name, value, min, max); float *f = new float; *f = value; printf("Value %f\n", value); //if(name=="BRIGHTNESS") max = 1024; myGui.addSlider(name, *f, min, max); cameraPropsIds[name] = i; } #endif #endif if(imagesFolder!="no-images") { this->imagesFolder = imagesFolder; imagePos = -1; nextImage(); } canDoCamera = false; #ifndef TEST_WITH_VIDEO if(result) { mode = CAMERA_MODE_FIREWIRE; } else if(videoGrabber.initGrabber(width, height)) { mode = CAMERA_MODE_QUICKTIME; canDoCamera = true; } else #endif { if(testVideoFile=="") { ofLogError("Video file path was empty, not gonna do a whole lot now"); } else { printf("Trying to load %s\n", ofToDataPath(testVideoFile).c_str()); } if(!testDataPlayer.loadMovie(testVideoFile)) { ofLogError("Couldn't load the movie, not gonna do shit now! %s", testVideoFile.c_str()); } else { testDataPlayer.play(); mode = CAMERA_MODE_RECORDED; } } }
/** * Starts the slideshow. */ void Photo_Viewer::startSlideshow() { slideTimer.start(getSlideshowSpeed(), this); nextImage(); update(); }
/** * Defines what happens after every timer interval */ void Photo_Viewer::timerEvent(QTimerEvent* event) { Q_UNUSED(event); nextImage(); update(); }
ImageView::ImageView(QWidget *parent) : QMainWindow(parent), ui(new Ui::ImageView) { ui->setupUi(this); setWindowTitle("MicroLab ImgP"); //! \brief connectActionToSlots //! connectActionToSlots(); newSonWidgets(); connect(ui->openDirAction, SIGNAL(triggered()), this, SLOT(openDir())); connect(ui->openFileAction, SIGNAL(triggered()), this, SLOT(openFile())); connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(save())); connect(ui->actionSave_As, SIGNAL(triggered()), this, SLOT(saveAs())); connect(ui->actionExit_4, SIGNAL(triggered()), this, SLOT(close())); connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(nextImage())); connect(ui->previousButton, SIGNAL(clicked()), this, SLOT(previousImage())); connect(ui->beginButton, SIGNAL(clicked()), this, SLOT(setBegin())); connect(ui->endButton, SIGNAL(clicked()), this, SLOT(setEnd())); connect(ui->slideShowButton, SIGNAL(clicked()), this, SLOT(slideShow())); connect(ui->slideShowDelaySlider, SIGNAL(valueChanged(int)), this, SLOT(setSlideShowDelay(int))); slideshowTimer = new QTimer(this); connect(slideshowTimer, SIGNAL(timeout()), this, SLOT(nextImage())); ui->imageNameLabel->setText(tr("Select a folder from the <b>file -> openDir</b> or <b>file->openFile</b> menu to view images or image..")); ui->openFileAction->setShortcut(tr("Ctrl+O")); setImage(":/images/Cover.jpg"); ui->previousButton->setEnabled(false); ui->nextButton->setEnabled(false); ui->beginButton->setEnabled(false); ui->endButton->setEnabled(false); ui->slideShowButton->setEnabled(false); ui->slideShowDelaySlider->setEnabled(false); ui->slideShowDelayLabel->setEnabled(false); ui->slideShowDelaySlider->setValue(15); //! NOTICE HERE ui->actionOpen_Recent_Files->setEnabled(false); ui->actionSave->setEnabled(false); ui->actionSave_As->setEnabled(true); ui->actionLecel_Set->setEnabled(false); //! @warning Bug setButtonIcon(ui->slideShowButton, ":/images/buttons/play.png", 48, 48); setButtonIcon(ui->nextButton, ":/images/buttons/next.png", 48, 48); setButtonIcon(ui->previousButton, ":/images/buttons/back.png", 48, 48); setButtonIcon(ui->beginButton, ":/images/buttons/rewind.png", 48, 48); setButtonIcon(ui->endButton, ":/images/buttons/fastfwd.png", 48, 48); setWindowTitle(tr("ImageView")); folderName = ""; imageNumber = 0; totalImages = 0; slideShowDelay = 2.0; QLabel *label = new QLabel("<a href = http://yajunyang.cn>connect me...</a>", this); connect(label, SIGNAL(linkActivated(QString)), this, SLOT(openUrl(QString))); ui->statusBar->insertWidget(0, label); }
//============================================================================ // main //============================================================================ int main() { //******************************************************* cout << "---------[Program start]----------" << endl; /* if (argc < 3) { fprintf(stderr, "Usage: mnist <k> <mnist path> [<nr train images> <nr test images>]\n"); return EXIT_FAILURE; } */ int k = 5; // TODO atoi(argv[1]); #ifdef PRINT cout << "k = " << k << endl; #endif string base = "/tmp/images/"; // TODO string base(argv[2]); LabelIterator *trainLabels = openLabels(base + "train-labels-idx1-ubyte"); ImageIterator *trainImages = openImages(base + "train-images-idx3-ubyte"); LabelIterator *testLabels = openLabels(base + "t10k-labels-idx1-ubyte"); ImageIterator *testImages = openImages(base + "t10k-images-idx3-ubyte"); if (trainLabels == 0 || trainImages == 0 || testLabels == 0 || testImages == 0) { cout << "One or more files couldn't be found! Make sure that following files are in the directory given as argument:\n" << "\ttrain-labels-idx1-ubyte\n" << "\ttrain-images-idx3-ubyte\n" << "\tt10k-labels-idx1-ubyte\n" << "\tt10k-images-idx3-ubyte\n" << endl; exit(-1); } /* trainLabels->count = 1000; trainImages->count = 1000; testLabels->count = 1000; testImages->count = 1000; */ unsigned char label; unsigned char *image; Points<unsigned char, unsigned char> training_points(trainImages->count, trainImages->rows * trainImages->columns); Points<unsigned char, unsigned char> test_points(testImages->count, testImages->rows * testImages->columns); #ifdef PRINT cout << trainImages->count << " " << trainImages->rows*trainImages->columns << endl; cout << "size: " << trainImages->rows*trainImages->columns << "\tcount: " << trainImages->count << endl; #endif int i = 0; Point<unsigned char, unsigned char> *trainPoint; while (hasNextLabel(trainLabels) && hasNextImage(trainImages)) { image = nextImage(trainImages); label = nextLabel(trainLabels); trainPoint = training_points.getPoint(i++); imageToPoint(trainPoint, label, image, (trainImages->columns *trainImages->rows)); #ifdef PRINT if ((i % 1000) == 0) cout << i << " training images loaded." << endl; #endif delete trainPoint; free(image); } i = 0; Point<unsigned char, unsigned char> *testPoint; while (hasNextLabel(testLabels) && hasNextImage(testImages)) { image = nextImage(testImages); label = nextLabel(testLabels); testPoint = test_points.getPoint(i++); imageToPoint(testPoint, label, image, (testImages->columns * testImages->rows)); #ifdef PRINT if ((i % 1000) == 0) cout << i << " test images loaded." << endl; #endif delete testPoint; free(image); } //******************************************************** unsigned char *result = classify(k, test_points, training_points); if (result != 0) { int errors = 0; for (int i = 0; i < test_points.getCount(); i++) { if (result[i] != test_points.getLabel(i)[0]) { errors++; } } float error_rate = (float) errors / (float) test_points.getCount(); printf("PPE:\t %d out of %d inaccurate classifications\n", errors, test_points.getCount()); printf("PPE:\t Error rate is %f\n", error_rate); free(result); } printf("PPE:\t Program finished\n"); return (0); }
void PhotoDetails::slotNextProp() { modifyImage(); emit nextImage(); }