ImageDisplay *MainWindow::createImageDisplay(int maxCurrentHeight, int maxCurrentWidth) { ImageDisplay *imageDisplay = new ImageDisplay(this, maxCurrentHeight, maxCurrentWidth); workspace->addWindow(imageDisplay); windowMenu->addAction(imageDisplay->windowMenuAction()); windowActionGroup->addAction(imageDisplay->windowMenuAction()); return imageDisplay; }
void FrameDisplayGL::paintGL() { ImageDisplay* displayedImage = image; glRasterPos2d(0,currHeight); // нижний левый угол glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // выравнивание glPixelZoom( 1 , 1 ); glDrawPixels( displayedImage->getWidth(), displayedImage->getHeight(), GL_RGB, GL_FLOAT, displayedImage->getImage() ); }
void MainWindow::convolutionDCTDialog() { if (activeImageDisplay()) { ConvolutionDialog convolutionDialog(this); connect(&convolutionDialog, SIGNAL(finalSelected(ImageDisplay *)), this, SLOT(performConvolutionDCT(ImageDisplay *))); QImage currentImage = activeImageDisplay()->getImage(); int imageHeight = currentImage.height(); int imageWidth = currentImage.width(); int newHeightAndWidth = ImageOperations::firstPowerOfTwoOfLargerDimension(imageWidth, imageHeight); int newHeight = newHeightAndWidth; int newWidth = newHeightAndWidth; QList<QAction*> list = windowActionGroup->actions(); QList<QAction*>::const_iterator stlIter1; for ( stlIter1 = list.begin(); stlIter1 != list.end(); ++stlIter1 ) { QAction* action = (*stlIter1); //QWidget * QAction::parentWidget () QWidget *widget = action->parentWidget(); ImageDisplay *imageDisplay = (ImageDisplay*) widget; if (activeImageDisplay() != imageDisplay) { QImage image = imageDisplay->getImage(); int maskHeight = image.height(); int maskWidth = image.width(); if (newHeight > 0 && newWidth > 0 && maskHeight > 0 && maskWidth > 0 && newHeight == maskHeight && newWidth == maskWidth) { convolutionDialog.addSelectCandidate(imageDisplay); } } } convolutionDialog.defineTargetMaskSize(newHeight, newWidth); convolutionDialog.refreshComboBox(); int result = convolutionDialog.exec(); if (result == QDialog::Rejected) return; } }
void MainWindow::open() { ImageDisplay *imageDisplay = createImageDisplay(workspace->height(), workspace->width()); if (imageDisplay->open()) { imageDisplay->show(); statusBar()->showMessage(tr("File loaded"), 2000); } else { imageDisplay->close(); statusBar()->showMessage(tr("Loading failed"), 2000); } }
int main(int argc, char **argv) { const char *img_file; if ( argc > 1 ) { img_file = argv[1]; } else { printf("Usage: %s <raw image file>\n", argv[0]); exit(-1); } FvRawReader *fvraw = new FvRawReader(img_file); unsigned char *buffer = malloc_buffer(fvraw->colorspace(), fvraw->pixel_width(), fvraw->pixel_height()); fvraw->set_buffer(buffer); fvraw->read(); ImageDisplay *display = new ImageDisplay(fvraw->pixel_width(), fvraw->pixel_height()); display->show(fvraw->colorspace(), buffer); SDLKeeper::init(SDL_INIT_EVENTTHREAD); bool quit = false; while (! quit) { SDL_Event event; if ( SDL_WaitEvent(&event) ) { switch (event.type) { case SDL_QUIT: quit = true; break; default: break; } } } delete display; free(buffer); delete(fvraw); SDLKeeper::quit(); return 0; }
ImageDisplay* displayImage ( const NICE::Image* image, const std::string& title, const bool copy ) { // make sure Qt is initialized if ( qApp == NULL ) { QtFramework::instance(); } // QWidget* mainWindow = NULL; // if (QtFramework::isInstanceInitialized()) { // mainWindow = QtFramework::instance().getMainWindow(); // } // ImageDisplay* display // = new ImageDisplay(mainWindow, title.c_str(), // (unsigned int)Qt::WType_TopLevel); ImageDisplay* display = new ImageDisplay(); display->setCaption ( title.c_str() ); display->setImage ( image, copy ); display->show(); return display; }
ImageDisplay* displayImageOverlay ( const NICE::ColorImage* image, const NICE::Image *overlay, const std::string& title, const bool copy ) { if ( ( image->width() != overlay->width() ) || ( image->height() != overlay->height() ) ) { fthrow ( Exception, "Image and overlay image must have the same dimensions." ); } // make sure Qt is initialized if ( qApp == NULL ) { QtFramework::instance(); } ImageDisplay *display = new ImageDisplay(); display->setCaption ( title.c_str() ); display->setImage ( image, copy ); display->setOverlayImage ( overlay ); display->show(); return display; }
void MainWindow::getPowerSpectrumUsingDCT() { if (activeImageDisplay()) { QImage image = activeImageDisplay()->getImage(); QString curFile = activeImageDisplay()->getCurFileWithStrippedName(); ImageOperations imageOperations(image); if (image.allGray()) { QImage RImage = imageOperations.DCTPowerSpectrum(Red); if (RImage.height() == 0) return; ImageDisplay *redImageDisplay = createImageDisplay(workspace->height(), workspace->width()); redImageDisplay->newFile("DCT Gray power spectrum of " + curFile); redImageDisplay->setImage(RImage); redImageDisplay->show(); } else { QImage RImage = imageOperations.DCTPowerSpectrum(Red); QImage GImage = imageOperations.DCTPowerSpectrum(Green); QImage BImage = imageOperations.DCTPowerSpectrum(Blue); if (RImage.height() == 0 || GImage.height() == 0 || BImage.height() == 0) return; ImageDisplay *redImageDisplay = createImageDisplay(workspace->height(), workspace->width()); redImageDisplay->newFile("DCT Red power spectrum of " + curFile); redImageDisplay->setImage(RImage); redImageDisplay->show(); ImageDisplay *greenImageDisplay = createImageDisplay(workspace->height(),workspace->width()); greenImageDisplay->newFile("DCT Green power spectrum of " + curFile); greenImageDisplay->setImage(GImage); greenImageDisplay->show(); ImageDisplay *blueImageDisplay = createImageDisplay(workspace->height(), workspace->width()); blueImageDisplay->newFile("DCT Blue power spectrum of " + curFile); blueImageDisplay->setImage(BImage); blueImageDisplay->show(); } } }
void MainWindow::newFile() { ImageDisplay *imageDisplay = createImageDisplay(workspace->height(), workspace->width()); imageDisplay->newFile(); imageDisplay->show(); }
int main(int argc, char **argv) { ArgumentParser *argp = new ArgumentParser(argc, argv, "h:f:c:"); if (argp->has_arg("h") && argp->has_arg("f")) // read image from file { const char *cascade_file = argp->arg("h"); const char *image_file = argp->arg("f"); JpegReader * reader = new JpegReader(image_file); unsigned char *buffer = malloc_buffer(YUV422_PLANAR, reader->pixel_width(), reader->pixel_height()); reader->set_buffer(buffer); reader->read(); FacesClassifier *classifier = new FacesClassifier(cascade_file, reader->pixel_width(), reader->pixel_height()); classifier->set_src_buffer(buffer, reader->pixel_width(), reader->pixel_height()); std::list<ROI> *rois = classifier->classify(); FilterROIDraw *roi_draw = new FilterROIDraw(); for (std::list<ROI>::iterator i = rois->begin(); i != rois->end(); ++i) { printf("ROI: start (%u, %u) extent %u x %u\n", (*i).start.x, (*i).start.y, (*i).width, (*i).height); roi_draw->set_dst_buffer(buffer, &(*i)); roi_draw->apply(); } ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height()); display->show(buffer); display->loop_until_quit(); delete display; delete rois; free(buffer); delete reader; delete classifier; } else if (argp->has_arg("h") && argp->has_arg("c")) // get images from camera { const char *cascade_file = argp->arg("h"); Camera *camera = NULL; try { camera = CameraFactory::instance(argp->arg("c")); camera->open(); camera->start(); } catch (Exception &e) { printf("Failed to open camera.\n"); delete camera; return (-1); } printf("successfully opened camera: w=%d h=%d\n", camera->pixel_width(), camera->pixel_height()); TimeTracker *tt = new TimeTracker(); unsigned int ttc_recognition = tt->add_class("Face recognition"); unsigned int loop_count = 0; IplImage *image = cvCreateImage(cvSize(camera->pixel_width(), camera->pixel_height()), IPL_DEPTH_8U, 3); IplImage *scaled_image = cvCreateImage(cvSize(camera->pixel_width() / 2, camera->pixel_height() / 2), IPL_DEPTH_8U, 3); FacesClassifier *classifier = new FacesClassifier(cascade_file, camera->pixel_width(), camera->pixel_height(), scaled_image, 1.2 /* scale factor */, 2 /* min neighbours */, CV_HAAR_DO_CANNY_PRUNING); unsigned char *display_buffer = (unsigned char *)malloc(camera->buffer_size()); ImageDisplay *display = new ImageDisplay(camera->pixel_width(), camera->pixel_height(), "QA Faces Classifier"); Drawer *drawer = new Drawer(); drawer->set_buffer(display_buffer, camera->pixel_width(), camera->pixel_height()); SDL_Event redraw_event; redraw_event.type = SDL_KEYUP; redraw_event.key.keysym.sym = SDLK_SPACE; SDL_PushEvent(&redraw_event); bool quit = false; while (!quit) { SDL_Event event; if (SDL_WaitEvent(&event)) { switch (event.type) { case SDL_QUIT: quit = true; break; case SDL_KEYUP: if (event.key.keysym.sym == SDLK_SPACE) { camera->capture(); if (camera->buffer() != NULL) { IplImageAdapter::convert_image_bgr(camera->buffer(), image); cvResize(image, scaled_image, CV_INTER_LINEAR); memcpy(display_buffer, camera->buffer(), camera->buffer_size()); tt->ping_start(ttc_recognition); std::list<ROI> *rois = classifier->classify(); tt->ping_end(ttc_recognition); camera->dispose_buffer(); bool first = true; for (std::list<ROI>::reverse_iterator i = rois->rbegin(); i != rois->rend(); ++i) { if (first) { drawer->set_color(127, 70, 200); } drawer->draw_rectangle(2 * i->start.x, 2 * i->start.y, 2 * i->width, 2 * i->height); if (first) { drawer->set_color(30, 30, 30); first = false; } } if (++loop_count % 15 == 0) { tt->print_to_stdout(); } display->show(display_buffer); } SDL_PushEvent(&redraw_event); } else if (event.key.keysym.sym == SDLK_ESCAPE) { quit = true; } break; default: break; } } } camera->stop(); camera->close(); delete camera; delete display; delete drawer; free(display_buffer); cvReleaseImage(&image); cvReleaseImage(&scaled_image); delete tt; } else { printf("Usage: %s -h <Haar cascade file> -f <Image file as JPEG>\n", argv[0]); printf(" or %s -h <Haar cascade file> -c <Camera argument string>\n", argv[0]); exit(-1); } delete argp; }
int main(int argc, char **argv) { const char *filename = "qatest.colormap"; if ( argc > 1 ) { filename = argv[1]; } printf("Creating simple one-plane colormap\n"); YuvColormap *cm = new YuvColormap(); for (unsigned int u = 100; u < 150; ++u) { for (unsigned int v = 100; v < 150; ++v) { cm->set(128, u, v, C_ORANGE); } } unsigned char *imgb = malloc_buffer(YUV422_PLANAR, cm->width() * 2, cm->height() * 2); cm->to_image(imgb); ImageDisplay *imgd = new ImageDisplay(cm->width() * 2, cm->height() * 2); imgd->show(imgb); imgd->loop_until_quit(); delete cm; printf("Trying to create colormap with illegal depth, should throw an exception.."); try { cm = new YuvColormap(3); printf(" Test failed, colormap was created\n"); delete cm; } catch (Exception &e) { printf(" Test succeeded, caught exception\n"); } printf("Trying colormap with depth of %u\n", BIGDEPTH); cm = new YuvColormap(BIGDEPTH); for (unsigned int d = 0; d < cm->depth(); ++d) { unsigned int y = 256 / cm->depth() * d; printf("d=%u y=%u u=[%u,%u] v=[%u,%u]\n", d, y, cm->depth() * d, cm->depth() * (d+1), cm->depth() * d, cm->depth() * (d+1)); for (unsigned int u = cm->deepness() / cm->depth() * d; u < cm->deepness() / cm->depth() * (d+1); ++u) { for (unsigned int v = cm->deepness() / cm->depth() * d; v < cm->deepness() / cm->depth() * (d+1); ++v) { cm->set(y, u, v, C_ORANGE); } } cm->to_image(imgb, d); imgd->show(imgb); imgd->loop_until_quit(); } printf("Saving colormap to a file\n"); ColormapFile cmf; cmf.add_colormap(cm); cmf.write(filename); ColormapFile::ColormapBlockVector *blocks = cmf.colormap_blocks(); printf("Written, created %zu blocks\n", blocks->size()); delete blocks; delete cm; cmf.clear(); printf("Reading colormap from file\n"); cmf.read(filename); Colormap *tcm = cmf.get_colormap(); if ( (cm = dynamic_cast<YuvColormap *>(tcm)) == 0 ) { printf("Error, did not get valid yuv colormap\n"); } else { printf("Showing all %u colormap levels\n", cm->depth()); for (unsigned int d = 0; d < cm->depth(); ++d) { cm->to_image(imgb, d); imgd->show(imgb); imgd->loop_until_quit(); } } delete cm; unsigned int depth = 4, width = 128, height = 128; printf("Trying colormap with low resolution, choosing %dx%dx%d\n", depth, width, height); cm = new YuvColormap(depth, width, height); printf("YuvColormap dimensions: %dx%dx%d\n", cm->depth(), cm->width(), cm->height()); ColormapFile cmfr(depth, width, height); delete cm; cmfr.write(filename); cmfr.clear(); cmfr.read(filename); cm = dynamic_cast<YuvColormap *>(cmfr.get_colormap()); printf("Read back colormap dimensions %dx%dx%d\n", cm->depth(), cm->width(), cm->height()); delete cm; //delete imgd; //free(imgb); return 0; }