void MainWindow::on_actionCapturar_triggered() { // qDebug()<<dispdefault_<<dispchoise_; if(operator!= (dispdefault_,dispchoise_)){ camera_->stop(); delete camera_; camera_ = new QCamera(dispchoise_); } else{ camera_ = new QCamera(dispdefault_); } captureB_ = new captureBuffer; camera_->setViewfinder(captureB_); camera_->setCaptureMode(QCamera::CaptureViewfinder); connect(captureB_, SIGNAL(signalImage(QImage)), this, SLOT(image1(QImage))); //Conectarnos al servidor host_ = setting_->value("viewer/host", "127.0.0.1").toString(); port_ = setting_->value("viewer/port", 9600).toInt(); //como la conexion es asincrona, esperamos a que se conecte. qDebug() << host_ << port_; tcpSocket_->connectToHost(host_, port_); connect(tcpSocket_, SIGNAL(connected()), this, SLOT(connected())); }
int main(int argc,char *argv[]) { QApplication app(argc,argv); { QTextCodec::setCodecForLocale(QTextCodec::codecForName(LOCAL_CODEC_)); QDir::addSearchPath("images",app.applicationDirPath()+"/Images"); QDir::addSearchPath("images",BUILD_PATH_); QDir::addSearchPath("images",BUILD_PATH_"/../Images"); } Window window; { QImage image1("images:000002"),image2("images:000003"); window.addImage( image1 )->setTitle("src1"); window.addImage( image2 )->setTitle("src2"); cv::Mat mat1 = qImage2OpencvMat( image1 ); cv::Mat mat2 = qImage2OpencvMat( image2 ); cv::Mat ans; cv::addWeighted(mat1,0.3,mat2,0.7,0.0 ,ans); window.addImage( opencvMat2QImage(ans) )->setTitle("add_0"); window.addImage( opencvMat2QImage( 0.7*mat1 + 0.3*mat2+cv::Scalar(0.1,0.2,0.3) ) )->setTitle("add_1"); } window.show(); return app.exec(); }
int main(int argc, char **argv){ if(argc<2){ std::cout<<"Need to specify the calibration file"<<std::endl; return 1; } Mat img1,img2; TwinCamera twin(0,1); twin.getDoubleImages(img1,img2); twin.loadCameraParameters(argv[1], img1, img2); Screen image1("Image1"); Screen image2("Image2"); Screen disp("Disparity"); StereoDepth stereoDepth; char c = 0; while(c!=27){ switch(c){ case '1': image1.putImage(img1); image2.putImage(img2); break; case '3': twin.getDoubleImages(img1,img2); twin.rectifyForStereo(img1, img2); stereoDepth.setImage1(img1); stereoDepth.setImage2(img2); if(stereoDepth.doDepth()){ disp.putImage(stereoDepth.getDisparity()); }break; } c = waitKey(10); } }
// Test that a draw that only partially covers the drawing surface isn't // interpreted as covering the entire drawing surface (i.e., exercise one of the // conditions of SkCanvas::wouldOverwriteEntireSurface()). DEF_TEST(Image_RetainSnapshot, reporter) { const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); surface->getCanvas()->clear(0xFF00FF00); SkPMColor pixels[4]; memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); const size_t dstRowBytes = 2 * sizeof(SkPMColor); SkAutoTUnref<SkImage> image1(surface->newImageSnapshot()); REPORTER_ASSERT(reporter, image1->readPixels(dstInfo, pixels, dstRowBytes, 0, 0)); for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) { REPORTER_ASSERT(reporter, pixels[i] == green); } SkPaint paint; paint.setXfermodeMode(SkXfermode::kSrc_Mode); paint.setColor(SK_ColorRED); surface->getCanvas()->drawRect(SkRect::MakeXYWH(1, 1, 1, 1), paint); SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); REPORTER_ASSERT(reporter, image2->readPixels(dstInfo, pixels, dstRowBytes, 0, 0)); REPORTER_ASSERT(reporter, pixels[0] == green); REPORTER_ASSERT(reporter, pixels[1] == green); REPORTER_ASSERT(reporter, pixels[2] == green); REPORTER_ASSERT(reporter, pixels[3] == red); }
void TestGPURayCaster::testSetImages() { vtkImageDataPtr data = vtkImageData::New(); cx::ImagePtr image1(new cx::Image("i1", data)); cx::ImagePtr image2(new cx::Image("i2", data)); cx::ImagePtr image3(new cx::Image("i3", data)); cx::ImagePtr image4(new cx::Image("i4", data)); cx::ImagePtr image5(new cx::Image("i5", data)); std::vector<cx::ImagePtr> images; uint64_t mTime = mRep->mActor->GetMTime(); images.push_back(image1); CPPUNIT_ASSERT_EQUAL((size_t)0, mRep->getImages().size()); mRep->setImages(images); CPPUNIT_ASSERT_EQUAL((size_t)1, mRep->getImages().size()); CPPUNIT_ASSERT_EQUAL(QString("i1"), mRep->getImages()[0]->getUid()); CPPUNIT_ASSERT(mRep->mActor->GetMTime() > mTime); mTime = mRep->mActor->GetMTime(); mRep->setImages(images); uint64_t mNewTime = mRep->mActor->GetMTime(); CPPUNIT_ASSERT_EQUAL(mTime, mNewTime); images.push_back(image2); images.push_back(image3); images.push_back(image4); images.push_back(image5); mRep->setImages(images); CPPUNIT_ASSERT_EQUAL((size_t)4, mRep->getImages().size()); CPPUNIT_ASSERT_EQUAL(QString("i1"), mRep->getImages()[0]->getUid()); CPPUNIT_ASSERT_EQUAL(QString("i2"), mRep->getImages()[1]->getUid()); CPPUNIT_ASSERT_EQUAL(QString("i3"), mRep->getImages()[2]->getUid()); CPPUNIT_ASSERT_EQUAL(QString("i4"), mRep->getImages()[3]->getUid()); }
int main( int argc, char * argv[] ) { const char * WINDOW_NAME = "Appended Images"; if( argc <= NUM_OF_ARGS ) { std::cerr << "Need " << NUM_OF_ARGS << " args. sift <image1> <image1_key> <image2> <image2_key>"; exit( -1 ); } ImageRAII image1( argv[1] ); ImageRAII image2( argv[3] ); std::pair< CvMat *, CvMat * > tmp1; std::pair< CvMat *, CvMat * > tmp2; std::pair< MatrixRAII, MatrixRAII > image1_keys; std::pair< MatrixRAII, MatrixRAII > image2_keys; tmp1 = readkeys( argv[2] ); image1_keys.first.matrix = tmp1.first; image1_keys.second.matrix = tmp1.second; tmp2 = readkeys( argv[4] ); image2_keys.first.matrix = tmp2.first; image2_keys.second.matrix = tmp2.second; ImageRAII appended_images = match( image1.image, image2.image, tmp1, tmp2 ); cvNamedWindow( WINDOW_NAME ); cvShowImage( WINDOW_NAME, appended_images.image ); cvWaitKey( 0 ); return 0; }
int Product::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = id(); break; case 1: *reinterpret_cast< QString*>(_v) = description(); break; case 2: *reinterpret_cast< QString*>(_v) = longdescription(); break; case 3: *reinterpret_cast< QString*>(_v) = longtext(); break; case 4: *reinterpret_cast< QString*>(_v) = image1(); break; case 5: *reinterpret_cast< QString*>(_v) = image2(); break; case 6: *reinterpret_cast< QString*>(_v) = image3(); break; case 7: *reinterpret_cast< QString*>(_v) = catid(); break; case 8: *reinterpret_cast< QString*>(_v) = subcatid(); break; } _id -= 9; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setId(*reinterpret_cast< QString*>(_v)); break; case 1: setDescription(*reinterpret_cast< QString*>(_v)); break; case 2: setLongDescription(*reinterpret_cast< QString*>(_v)); break; case 3: setLongText(*reinterpret_cast< QString*>(_v)); break; case 4: setImage1(*reinterpret_cast< QString*>(_v)); break; case 5: setImage2(*reinterpret_cast< QString*>(_v)); break; case 6: setImage2(*reinterpret_cast< QString*>(_v)); break; case 7: setCatId(*reinterpret_cast< QString*>(_v)); break; case 8: setSubCatId(*reinterpret_cast< QString*>(_v)); break; } _id -= 9; } else if (_c == QMetaObject::ResetProperty) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 9; } else if (_c == QMetaObject::RegisterPropertyMetaType) { if (_id < 9) *reinterpret_cast<int*>(_a[0]) = -1; _id -= 9; } #endif // QT_NO_PROPERTIES return _id; }
void DragDropRect::dropEvent(QGraphicsSceneDragDropEvent *event)//Bilder die hier reingezogen werden, werden angezeigt { image = qvariant_cast<QImage>(event->mimeData()->imageData()); //pixmap = qvariant_cast<QPixmap>(event->mimeData()->imageData()); dragOver=true; event->setAccepted(true); qDebug()<<event->mimeData()->text(); QImage image1(event->mimeData()->data("file"));//erstellt das QImage mit hilfe des Pfads vom gedropted bild this->image = image1; parentItem()->update(); }
double run_test_npcr(struct img_info_t *img_info) { cimg_library::CImg<unsigned int> image1(img_info->origin.c_str()); cimg_library::CImg<unsigned int> image2(img_info->encrypted.c_str()); double number_of_pixels = image1.width() * image1.height(); double npcr = 0; // just compare images with the same size, stop if not if (image1.width() != image2.width() || image1.height() != image2.height()) return -1.0; // calculate npcr = (1/number_of_pixel) * sum(D(i,j) * 100 // D(i,j) = 1 , if image1(i,j) != image2(i,j) // D(i,j) = 0 , if image1(i,j) == image2(i,j) cimg_forXY(image1, x, y) { if (image1(x, y, 0, 0) != image2(x, y, 0, 0)) npcr++; } return (npcr * 100) / number_of_pixels; }
void DeconvolveTest::testDisk() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testDisk() begin"); DiskImage image1(ImageSize(256,256), ImagePoint(47,62), 1, 1); ImagePtr iptr = ImagePtr(new Image<double>(image1)); DiskImage image2(ImageSize(256,256), ImagePoint(128,111), 1, 1); BasicDeconvolutionOperator decon(image2); ImagePtr fq = decon(iptr); io::FITSout out("tmp/deconvolve-disk.fits"); out.setPrecious(false); out.write(fq); debug(LOG_DEBUG, DEBUG_LOG, 0, "testDisk() end"); }
void MultiVolumeRaycaster::updateResult(DataContainer& dataContainer) { ImageRepresentationGL::ScopedRepresentation image1(dataContainer, p_sourceImage1.getValue()); ImageRepresentationGL::ScopedRepresentation image2(dataContainer, p_sourceImage2.getValue()); ImageRepresentationGL::ScopedRepresentation image3(dataContainer, p_sourceImage3.getValue()); ScopedTypedData<CameraData> camera(dataContainer, p_camera.getValue()); ScopedTypedData<RenderData> geometryImage(dataContainer, p_geometryImageId.getValue(), true); ScopedTypedData<LightSourceData> light(dataContainer, p_lightId.getValue()); std::vector<const ImageRepresentationGL*> images; if (image1) { images.push_back(image1); if (getInvalidationLevel() & INVALID_VOXEL_HIERARCHY1){ _vhm1->createHierarchy(image1, p_transferFunction1.getTF()); validate(INVALID_VOXEL_HIERARCHY1); } } if (image2) { images.push_back(image2); if (getInvalidationLevel() & INVALID_VOXEL_HIERARCHY2){ _vhm2->createHierarchy(image2, p_transferFunction2.getTF()); validate(INVALID_VOXEL_HIERARCHY2); } } if (image3) { images.push_back(image3); if (getInvalidationLevel() & INVALID_VOXEL_HIERARCHY3){ _vhm3->createHierarchy(image3, p_transferFunction3.getTF()); validate(INVALID_VOXEL_HIERARCHY3); } } if (images.size() >= 3 && camera != nullptr) { auto eepp = computeEntryExitPoints(images, camera, geometryImage); dataContainer.addData(p_outputImageId.getValue() + ".entrypoints", eepp.first); dataContainer.addData(p_outputImageId.getValue() + ".exitpoints", eepp.second); auto rc = performRaycasting(dataContainer, images, camera, eepp.first, eepp.second, light); dataContainer.addData(p_outputImageId.getValue(), rc); } else { LDEBUG("No suitable input data found!"); } }
bool compareImages(char* imagePath1, char* imagePath2) { QImage image1(imagePath1); QImage image2(imagePath2); if (image1.isNull()) { qDebug() << "Image 1 couldn't be loaded."; return false; } if (image2.isNull()) { qDebug() << "Image 2 couldn't be loaded."; return false; } return (image1 == image2); }
double greplace::gpu::find_statistic(std::vector<std::string> images, double r0, double rf, cv::gpu::CascadeClassifier_GPU & classifier) { std::vector<double> statistic; for (size_t i = 0; i < images.size(); i ++) { std::string image1_location = images[i]; for (size_t j = 0; j < images.size(); j ++) { std::string image2_location = images[j]; cv::gpu::GpuMat image1(cv::imread(image1_location, CV_LOAD_IMAGE_GRAYSCALE)); cv::gpu::GpuMat image2(cv::imread(image2_location, CV_LOAD_IMAGE_GRAYSCALE)); try { cv::gpu::GpuMat face1 = greplace::gpu::find_face(image1, classifier, THRESHOLD); cv::gpu::GpuMat face2 = greplace::gpu::find_face(image2, classifier, THRESHOLD); cv::Mat face1_cpu, face2_cpu, face3_cpu; face1.download(face1_cpu); face2.download(face2_cpu); cv::resize(face2_cpu, face2_cpu, face1_cpu.size()); face2.upload(face2_cpu); cv::gpu::GpuMat face3 = greplace::gpu::blend(face1, face2, r0, rf); face3.download(face3_cpu); cv::imshow("face1", face1_cpu); cv::imshow("face2", face2_cpu); cv::imshow("Blended", face3_cpu); cv::waitKey(10); cv::Mat hist1 = greplace::hist(face1_cpu); cv::Mat hist2 = greplace::hist(face2_cpu); cv::Mat hist3 = greplace::hist(face3_cpu); double s = greplace::hist_correlation(hist1, hist3) + greplace::hist_correlation(hist2, hist3); statistic.push_back(s); } catch (...) { // One of the faces couldn't be found because the angle of the image // is too great for the frontal face classifier } } } return greplace::mean(statistic); }
void MultiVolumeRaycaster::updateProperties(DataContainer& dataContainer) { ImageRepresentationGL::ScopedRepresentation image1(dataContainer, p_sourceImage1.getValue()); ImageRepresentationGL::ScopedRepresentation image2(dataContainer, p_sourceImage2.getValue()); ImageRepresentationGL::ScopedRepresentation image3(dataContainer, p_sourceImage3.getValue()); if (image1) p_transferFunction1.setImageHandle(image1.getDataHandle()); else p_transferFunction1.setImageHandle(DataHandle(nullptr)); if (image2) p_transferFunction2.setImageHandle(image2.getDataHandle()); else p_transferFunction2.setImageHandle(DataHandle(nullptr)); if (image3) p_transferFunction3.setImageHandle(image3.getDataHandle()); else p_transferFunction3.setImageHandle(DataHandle(nullptr)); }
void TerrainWeightEditor::DecomposeImageToCanvases(const QImage& image) { QLabel *canvas1 = editor_widget_->findChild<QLabel *>("canvas_1"); QLabel *canvas2 = editor_widget_->findChild<QLabel *>("canvas_2"); QLabel *canvas3 = editor_widget_->findChild<QLabel *>("canvas_3"); QLabel *canvas4 = editor_widget_->findChild<QLabel *>("canvas_4"); assert(canvas1 && canvas2 && canvas3 && canvas4); int width = image.width(); int height = image.height(); QImage::Format format = image.format(); QImage image1(width,height,format); QImage image2(width,height,format); QImage image3(width,height,format); QImage image4(width,height,format); for(int i=0;i<width;i++) { for(int j=0; j<height;j++) { QRgb color = image.pixel(i,j); int alpha = qAlpha(color); int red = qRed(color); int green = qGreen(color); int blue = qBlue(color); image1.setPixel(i,j, QColor(red,red,red).rgba()); image2.setPixel(i,j, QColor(green,green,green).rgba()); image3.setPixel(i,j, QColor(blue,blue,blue).rgba()); image4.setPixel(i,j, QColor(alpha,alpha,alpha).rgba()); } } canvas1->setPixmap(QPixmap::fromImage(image1)); canvas2->setPixmap(QPixmap::fromImage(image2)); canvas3->setPixmap(QPixmap::fromImage(image3)); canvas4->setPixmap(QPixmap::fromImage(image4)); }
void TestCube::setPairs(vector<shared_ptr<ImagePair>> &pairs) { shared_ptr<Image> image1(new Image()); shared_ptr<Image> image2(new Image()); shared_ptr<Image> image3(new Image()); shared_ptr<ImagePair> pair1(new ImagePair()); shared_ptr<ImagePair> pair2(new ImagePair()); pair1->image1 = image1; pair1->image2 = image2; pair2->image1 = image2; pair2->image2 = image3; TestCube::setKeypointsImg1(image1->keypoints_); TestCube::setKeypointsImg2(image2->keypoints_); TestCube::setKeypointsImg3(image3->keypoints_); TestCube::setMatches(8, pair1->matches); TestCube::setMatches(9, pair2->matches); pairs.push_back(pair1); pairs.push_back(pair2); }
/* * Constructs a Chintz_base which is a child of 'parent', with the * name 'name' and widget flags set to 'f' * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */ Chintz_base::Chintz_base( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) { if ( !name ) setName( "Chintz_base" ); resize( 790, 620 ); QFont f( font() ); f.setFamily( "adobe-helvetica" ); setFont( f ); setCaption( tr( "Chintz v0.2" ) ); QToolTip::add( this, tr( "" ) ); altered_state=false; //Make the menu bar at the top of the widget menu=new QMenuBar(this); menu->setSeparator(QMenuBar::InWindowsStyle); QPopupMenu *file=new QPopupMenu(this); file->insertItem("&New Control File",this,SLOT(Clear()),CTRL+Key_N); file->insertItem("&Open Control File",this,SLOT(OpenChildControlFile()),CTRL+Key_O); file->insertItem("&Save Control File",this,SLOT(WriteTheOutput()),CTRL+Key_S); file->insertItem("&Save Control File As...",this,SLOT(SaveAs())); file->insertItem("&Quit",this,SLOT(Close()),CTRL+Key_Q); QPopupMenu *help=new QPopupMenu(this); menu->insertSeparator(0); help->insertItem("&About",this,SLOT(About())); help->insertItem("&Contents",this,SLOT(Help())); menu->insertItem("&File",file,4); menu->insertItem("&Help",help,7); QPixmap image0( ( const char** ) image0_data ); QPixmap image1( ( const char** ) image1_data ); QPixmap image2( ( const char** ) image2_data ); Framebutt = new QFrame( this, "Framebutt" ); Framebutt->setGeometry( QRect( 10, 30, 750, 40 ) ); Framebutt->setFrameShape( QFrame::Panel ); Framebutt->setFrameShadow( QFrame::Raised ); Newby = new QPushButton( Framebutt, "Newby" ); Newby->setGeometry( QRect( 10, 10, 24, 22 ) ); Newby->setText( tr( "" ) ); Newby->setPixmap( image0 ); QToolTip::add( Newby, tr( "New Control File" ) ); Save = new QPushButton( Framebutt, "Save" ); Save->setGeometry( QRect( 70, 10, 22, 22 ) ); Save->setText( tr( "" ) ); Save->setPixmap( image1 ); QToolTip::add( Save, tr( "Save Control File" ) ); OPeny = new QPushButton( Framebutt, "OPeny" ); OPeny->setGeometry( QRect( 40, 10, 24, 22 ) ); OPeny->setText( tr( "" ) ); OPeny->setPixmap( image2 ); QToolTip::add( OPeny, tr( "Open Control File" ) ); connect( Newby, SIGNAL( clicked() ), this, SLOT( Clear() )); connect( Save, SIGNAL( clicked() ), this, SLOT( WriteTheOutput() ) ); connect( OPeny, SIGNAL( clicked() ), this, SLOT( OpenChildControlFile() )); CONTROLFILENAME=""; CONTROLFILENAMELine=new QLineEdit(Framebutt,"CNTRL"); CONTROLFILENAMELine->setGeometry( QRect( 490, 10, 224, 22 ) ); CONTROLFILENAMELine->setText( tr( "" ) ); connect(CONTROLFILENAMELine, SIGNAL( textChanged(const QString&) ), this, SLOT( altered() ) ); connect(CONTROLFILENAMELine, SIGNAL( returnPressed() ), this, SLOT( control() ) ); QLabel* Cntrl=new QLabel(Framebutt,"Cntrlabel"); Cntrl->setGeometry( QRect( 380, 10, 100, 22 ) ); Cntrl->setText(tr("Child Control File")); QFont Cf=Cntrl->font(); Cf.setBold(true); Cntrl->setFont(Cf); Br = new QToolButton( Framebutt, "Br" ); Br->setGeometry( QRect( 714, 10, 20, 23 ) ); Br->setText( tr( "..." ) ); QToolTip::add( Br, tr( "browse" ) ); connect(Br, SIGNAL( clicked() ), this, SLOT( ChildFileSelect() ) ); QPalette pal; QColorGroup cg; cg.setColor( QColorGroup::Foreground, QColor( 200, 110, 250) ); cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) ); pal.setActive(cg); pal.setInactive(cg); Cntrl->setPalette(pal); StatusFrame = new QFrame( this, "StatusFrame" ); StatusFrame->setGeometry( QRect( 10, 590, 751, 21 ) ); StatusFrame->setFrameShape( QFrame::StyledPanel ); StatusFrame->setFrameShadow( QFrame::Raised ); Status = new QLabel( StatusFrame, "Status" ); Status->setGeometry( QRect( 10, 1, 101, 16 ) ); cg.setColor( QColorGroup::Foreground, QColor( 255, 0, 0) ); cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) ); pal.setActive(cg); pal.setInactive(cg); Status->setPalette(pal); #include "generated_chintz_base_constructor_insert" QFileInfo q(".ChintzDefaults"); if (q.exists()){ ReadChildControlFile(".ChintzDefaults"); altered_state=false; Status->setText(""); } }
int main() { osgViewer::Viewer viewer; osg::ref_ptr<osg::Group> root (new osg::Group); osg::ref_ptr<osg::PositionAttitudeTransform> objectPat (new osg::PositionAttitudeTransform); osg::ref_ptr<osg::PositionAttitudeTransform> quadPat (new osg::PositionAttitudeTransform); osg::ref_ptr<osg::MatrixTransform> terrainScaleMAT (new osg::MatrixTransform); osg::Matrix terrainScaleMatrix; terrainScaleMatrix.makeScale(0.05f,0.05f,0.03f); osg::Vec3f objectPosTrans = osg::Vec3f(-1,3,5); osg::Vec3f quadPos = osg::Vec3f(5,0,0.5f); osg::Vec3f quadPos2 = osg::Vec3f(-5,0,0); //osg::Vec3f terrainScale = osg::Vec3f(0.5f,0.5f,0.5f); //Tuto9: Lighting code osg::ref_ptr<osg::Group> lightGroup (new osg::Group); osg::ref_ptr<osg::StateSet> lightSS (root->getOrCreateStateSet()); osg::ref_ptr<osg::LightSource> lightSource1 = new osg::LightSource; osg::ref_ptr<osg::LightSource> lightSource2 = new osg::LightSource; // create a local light. osg::Vec4f lightPosition (osg::Vec4f(-5.0,-2.0,3.0,1.0f)); osg::ref_ptr<osg::Light> myLight = new osg::Light; myLight->setLightNum(1); myLight->setPosition(lightPosition); myLight->setAmbient(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); myLight->setDiffuse(osg::Vec4(0.8f,0.8f,0.8f,1.0f)); myLight->setConstantAttenuation(1.0f); lightSource1->setLight(myLight.get()); lightSource1->setLocalStateSetModes(osg::StateAttribute::ON); lightSource1->setStateSetModes(*lightSS,osg::StateAttribute::ON); //osg::StateSet* lightSS (lightGroup->getOrCreateStateSet()); // create a local light. osg::Vec4f lightPosition2 (osg::Vec4f(2.0,-1.0,3.0,1.0f)); osg::ref_ptr<osg::Light> myLight2 = new osg::Light; myLight2->setLightNum(0); myLight2->setPosition(lightPosition2); myLight2->setAmbient(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); myLight2->setDiffuse(osg::Vec4(0.8f,0.1f,0.1f,1.0f)); myLight2->setConstantAttenuation(1.0f); lightSource2->setLight(myLight2.get()); lightSource2->setLocalStateSetModes(osg::StateAttribute::ON); lightSource2->setStateSetModes(*lightSS,osg::StateAttribute::ON); lightGroup->addChild(lightSource1.get()); lightGroup->addChild(lightSource2.get()); //Light markers: small spheres osg::ref_ptr<osg::Geode> lightMarkerGeode (new osg::Geode); lightMarkerGeode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(-5.0f,-2.0f,3.0f),0.5f))); //lightMarkerGeode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); //Second light marker lightMarkerGeode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(2.0f,-1.0f,3.0f),0.5f))); //The geode of the capsule osg::ref_ptr<osg::Geode> myshapegeode (new osg::Geode); objectPat->addChild(myshapegeode.get()); objectPat->setPosition(objectPosTrans); //quadPat->addChild(myQuad().get()); quadPat->setPosition(quadPos); myshapegeode->addDrawable(new osg::ShapeDrawable(new osg::Capsule(osg::Vec3f(),1,2))); //Getting the state set of the geode osg::ref_ptr<osg::StateSet> nodess (myshapegeode->getOrCreateStateSet()); //loading texture image object osg::ref_ptr<osg::Image> image (osgDB::readImageFile("Fieldstone.png")); //Bind the image to a 2D texture object osg::ref_ptr<osg::Texture2D> tex (new osg::Texture2D); tex->setImage(image.get()); //Release the image memory on the GPU after using it! //tex->setUnRefImageDataAfterApply(true); //Applying texture on the object nodess->setTextureAttributeAndModes(0,tex.get(),osg::StateAttribute::ON); //Loading the terrain node osg::ref_ptr<osg::Node> terrainnode (osgDB::readNodeFile("JoeDirt.flt")); //osg::ref_ptr<osg::Node> terrainnode (osgDB::readNodeFile("Terrain2.3ds")); terrainScaleMAT->addChild(terrainnode.get()); terrainScaleMAT->setMatrix(terrainScaleMatrix); //Tutorial 11: Billboarding stuff osg::ref_ptr<osg::Billboard> quadBillBoard = new osg::Billboard(); osg::ref_ptr<osg::StateSet> billSS (quadBillBoard->getOrCreateStateSet()); //Adding texture to the billboards osg::ref_ptr<osg::Image> image1 (osgDB::readImageFile("foo.png")); if (image1.get() == 0) { std::cerr << "Error loading 'foo.png'.\n"; exit (EXIT_FAILURE); } osg::ref_ptr<osg::Texture2D> texture (new osg::Texture2D); texture->setImage (image1.get()); billSS->setTextureAttributeAndModes (0, // unit texture.get(), osg::StateAttribute::ON); root->addChild(quadBillBoard.get()); quadBillBoard->setMode(osg::Billboard::AXIAL_ROT); quadBillBoard->setAxis(osg::Vec3(0.0f,0.0f,1.0f)); quadBillBoard->setNormal(osg::Vec3(0.0f,-1.0f,0.0f)); quadBillBoard->addDrawable(myQuad().get(),quadPos); quadBillBoard->addDrawable(myQuad().get(),quadPos2); //adding the terrain node to the root node //root->addChild(myQuad().get()); //root->addChild(quadPat.get()); root->addChild(objectPat.get()); root->addChild(terrainScaleMAT.get()); //Tuto 9: lighting code root->addChild(lightGroup.get()); //Tuto 9: Adding the light marker geode root->addChild(lightMarkerGeode.get()); //Adding the fog to the root node //root->setStateSet(setFogState().get()); // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); //Stats Event Handler s key viewer.addEventHandler(new osgViewer::StatsHandler); //Windows size handler viewer.addEventHandler(new osgViewer::WindowSizeHandler); //Threading Handler activate with the 'm' key viewer.addEventHandler(new osgViewer::ThreadingHandler); // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(root.get()); viewer.setSceneData( root.get() ); return (viewer.run()); }
void UIVMPreviewWindow::repaintBGImages() { /* Delete the old images: */ if (m_pbgImage) { delete m_pbgImage; m_pbgImage = 0; } if (m_pGlossyImg) { delete m_pGlossyImg; m_pGlossyImg = 0; } /* Check that there is enough room for our fancy stuff. * If not we just draw nothing (the border and the blur radius). */ QRect cr = contentsRect(); if (cr.width() < 41 || cr.height() < 41) return; QPalette pal = palette(); m_wRect = cr.adjusted(10, 10, -10, -10); m_vRect = m_wRect.adjusted(m_vMargin, m_vMargin, -m_vMargin, -m_vMargin).adjusted(-3, -3, 3, 3); /* First draw the shadow. Its a rounded rectangle which get blurred: */ QImage imageW(cr.size(), QImage::Format_ARGB32); QColor bg = pal.color(QPalette::Base); bg.setAlpha(0); /* We want blur to transparent _and_ whatever the base color is. */ imageW.fill(bg.rgba()); QPainter pW(&imageW); pW.setBrush(QColor(30, 30, 30)); /* Dark gray */ pW.setPen(Qt::NoPen); pW.drawRoundedRect(QRect(QPoint(0, 0), cr.size()).adjusted(10, 10, -10, -10), m_vMargin, m_vMargin); pW.end(); /* Blur the rectangle */ QImage imageO(cr.size(), QImage::Format_ARGB32); blurImage(imageW, imageO, 10); QPainter pO(&imageO); /* Now paint the border with a gradient to get a look of a monitor: */ QRect rr = QRect(QPoint(0, 0), cr.size()).adjusted(10, 10, -10, -10); QLinearGradient lg(0, rr.y(), 0, rr.height()); QColor base(200, 200, 200); /* light variant */ // QColor base(80, 80, 80); /* Dark variant */ lg.setColorAt(0, base); lg.setColorAt(0.4, base.darker(300)); lg.setColorAt(0.5, base.darker(400)); lg.setColorAt(0.7, base.darker(300)); lg.setColorAt(1, base); pO.setBrush(lg); pO.setPen(QPen(base.darker(150), 1)); pO.drawRoundedRect(rr, m_vMargin, m_vMargin); pO.end(); /* Make a copy of the new bg image: */ m_pbgImage = new QImage(imageO); /* Now the glossy overlay has to be created. * Start with defining a nice looking painter path. */ QRect gRect = QRect(QPoint(0, 0), m_vRect.size()); QPainterPath glossyPath(QPointF(gRect.x(), gRect.y())); glossyPath.lineTo(gRect.x() + gRect.width(), gRect.y()); glossyPath.lineTo(gRect.x() + gRect.width(), gRect.y() + gRect.height() * 1.0/3.0); glossyPath.cubicTo(gRect.x() + gRect.width() / 2.0, gRect.y() + gRect.height() * 1.0/3.0, gRect.x() + gRect.width() / 2.0, gRect.y() + gRect.height() * 2.0/3.0, gRect.x(), gRect.y() + gRect.height() * 2.0/3.0); glossyPath.closeSubpath(); /* Paint the glossy path on a QImage: */ QImage image(m_vRect.size(), QImage::Format_ARGB32); QColor bg1(Qt::white); /* We want blur to transparent _and_ white. */ bg1.setAlpha(0); image.fill(bg1.rgba()); QPainter painter(&image); painter.fillPath(glossyPath, QColor(255, 255, 255, 80)); painter.end(); /* Blur the image to get a much more smooth feeling */ QImage image1(m_vRect.size(), QImage::Format_ARGB32); blurImage(image, image1, 7); m_pGlossyImg = new QImage(image1); /* Repaint: */ update(); }
QImage DragDropRect::getImage() { QImage image1(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/bilder/icon0.png")); return image; }
void convolute() { const string filename = "61.030.tif"; REAL sigma = 3.2; int nbShift = 15; double epsilon = 0.001; int surEch = 10; ConvolutionKernel1D<INT> kernel; integralGaussianKernel<INT>(sigma, nbShift, epsilon, surEch, kernel); const vector<INT> &c = kernel.coefficients(); cout << "kernel.size() = " << kernel.size() << endl; for (size_t i = 0; i < kernel.size(); i++) cout << c[i] << ' '; cout << endl; ConvolutionHandler<U_INT2> convolutionHandler; cConvolSpec<U_INT2> *convolution1d = convolutionHandler.getConvolution(kernel); cout << "convolution is " << ( !convolution1d->IsCompiled() ? "not " : "") << "compiled" << endl; Tiff_Im tiff(filename.c_str()); cout << "[" << filename << "]: " << tiff.sz() << 'x' << tiff.nb_chan() << ' ' << eToString(tiff.type_el()) << endl; Im2DGen src_gen = tiff.ReadIm(); Im2D_U_INT2 image0; if (tiff.type_el() != GenIm::u_int1) ELISE_ERROR_EXIT("bad type"); { U_INT1 *src = ((Im2D_U_INT1 *) &src_gen)->data_lin(); image0.Resize(tiff.sz()); cout << "src_gen.sz() = " << src_gen.sz() << " image0.sz() = " << image0.sz() << endl; U_INT2 *dst = image0.data_lin(); size_t i = size_t(image0.tx()) * size_t(image0.ty()); while (i--) *dst++ = (U_INT2)(*src++) * 257; } Im2D_U_INT2 image1(image0.tx(), image0.ty()); Im2D_U_INT2 *src = &image0, *dst = &image1; int nbConvol = 10; while (nbConvol--) { convolution<U_INT2>((const U_INT2 **)src->data(), src->tx(), src->ty(), *convolution1d, dst->data()); ElSwap<Im2D_U_INT2 *>(src, dst); } Im2D_U_INT1 imageToWrite(src->tx(), src->ty()); { U_INT2 *itSrc = src->data_lin(); U_INT1 *itDst = imageToWrite.data_lin(); size_t i = size_t(src->tx()) * size_t(src->ty()); while (i--) *itDst++ = (U_INT1)((*itSrc++) / 257); } ELISE_COPY ( imageToWrite.all_pts(), imageToWrite.in(), Tiff_Im( "toto.tif", imageToWrite.sz(), GenIm::u_int1, Tiff_Im::No_Compr, Tiff_Im::BlackIsZero, Tiff_Im::Empty_ARG ).out() ); }
int main(int argc, char **argv) { #ifdef CONSOLE_APPLICATION QApplication app(argc, argv, QApplication::Tty); #else QApplication app(argc, argv); #endif #ifdef DO_QWS_DEBUGGING qt_show_painter_debug_output = false; #endif DeviceType type = WidgetType; bool checkers_background = true; QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied; QLocale::setDefault(QLocale::c()); QStringList files; bool interactive = false; bool printdlg = false; bool highres = false; bool show_cmp = false; int width = 800, height = 800; bool verboseMode = false; #ifndef QT_NO_OPENGL QGLFormat f = QGLFormat::defaultFormat(); f.setSampleBuffers(true); f.setStencil(true); f.setAlpha(true); f.setAlphaBufferSize(8); QGLFormat::setDefaultFormat(f); #endif char *arg; for (int i=1; i<argc; ++i) { arg = argv[i]; if (*arg == '-') { QString option = QString(arg + 1).toLower(); if (option == "widget") type = WidgetType; else if (option == "bitmap") type = BitmapType; else if (option == "pixmap") type = PixmapType; else if (option == "image") type = ImageType; else if (option == "imageformat") { Q_ASSERT_X(i + 1 < argc, "main", "-imageformat must be followed by a value"); QString format = QString(argv[++i]).toLower(); imageFormat = QImage::Format_Invalid; static const unsigned int formatCount = sizeof(imageFormats) / sizeof(imageFormats[0]); for (int ff = 0; ff < formatCount; ++ff) { if (QLatin1String(imageFormats[ff].name) == format) { imageFormat = imageFormats[ff].format; break; } } if (imageFormat == QImage::Format_Invalid) { printf("Invalid image format. Available formats are:\n"); for (int ff = 0; ff < formatCount; ++ff) printf("\t%s\n", imageFormats[ff].name); return -1; } } else if (option == "imagemono") type = ImageMonoType; else if (option == "imagewidget") type = ImageWidgetType; #ifndef QT_NO_OPENGL else if (option == "opengl") type = OpenGLType; else if (option == "pbuffer") type = OpenGLPBufferType; #endif #ifdef USE_CUSTOM_DEVICE else if (option == "customdevice") type = CustomDeviceType; else if (option == "customwidget") type = CustomWidgetType; #endif else if (option == "pdf") type = PdfType; else if (option == "ps") type = PsType; else if (option == "picture") type = PictureType; else if (option == "printer") type = PrinterType; else if (option == "highres") { type = PrinterType; highres = true; } else if (option == "printdialog") { type = PrinterType; printdlg = true; } else if (option == "grab") type = GrabType; else if (option == "i") interactive = true; else if (option == "v") verboseMode = true; else if (option == "commands") { displayCommands(); return 0; } else if (option == "w") { Q_ASSERT_X(i + 1 < argc, "main", "-w must be followed by a value"); width = atoi(argv[++i]); } else if (option == "h") { Q_ASSERT_X(i + 1 < argc, "main", "-h must be followed by a value"); height = atoi(argv[++i]); } else if (option == "cmp") { show_cmp = true; } else if (option == "bg-white") { checkers_background = false; } } else { #if defined (Q_WS_WIN) QString input = QString::fromLocal8Bit(argv[i]); if (input.indexOf('*') >= 0) { QFileInfo info(input); QDir dir = info.dir(); QFileInfoList infos = dir.entryInfoList(QStringList(info.fileName())); for (int ii=0; ii<infos.size(); ++ii) files.append(infos.at(ii).absoluteFilePath()); } else { files.append(input); } #else files.append(QString(argv[i])); #endif } } PaintCommands pcmd(QStringList(), 800, 800); pcmd.setVerboseMode(verboseMode); pcmd.setType(type); pcmd.setCheckersBackground(checkers_background); QWidget *activeWidget = 0; if (interactive) { runInteractive(); if (!files.isEmpty()) interactive_widget->load(files.at(0)); } else if (files.isEmpty()) { printHelp(); return 0; } else { for (int j=0; j<files.size(); ++j) { const QString &fileName = files.at(j); QStringList content; QFile file(fileName); QFileInfo fileinfo(file); if (file.open(QIODevice::ReadOnly)) { QTextStream textFile(&file); QString script = textFile.readAll(); content = script.split("\n", QString::SkipEmptyParts); } else { printf("failed to read file: '%s'\n", qPrintable(fileName)); continue; } pcmd.setContents(content); if (show_cmp) { QString pmFile = QString(files.at(j)).replace(".qps", "_qps") + ".png"; qDebug() << pmFile << QFileInfo(pmFile).exists(); QPixmap pixmap(pmFile); if (!pixmap.isNull()) { QLabel *label = createLabel(); label->setWindowTitle("VERIFY: " + pmFile); label->setPixmap(pixmap); label->show(); } } switch (type) { case WidgetType: { OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>; qWidget->setVerboseMode(verboseMode); qWidget->setType(type); qWidget->setCheckersBackground(checkers_background); qWidget->m_filename = files.at(j); qWidget->setWindowTitle(fileinfo.filePath()); qWidget->m_commands = content; qWidget->resize(width, height); qWidget->show(); activeWidget = qWidget; break; } case ImageWidgetType: { OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>; qWidget->setVerboseMode(verboseMode); qWidget->setType(type); qWidget->setCheckersBackground(checkers_background); qWidget->m_filename = files.at(j); qWidget->setWindowTitle(fileinfo.filePath()); qWidget->m_commands = content; qWidget->resize(width, height); qWidget->show(); activeWidget = qWidget; break; } #ifndef QT_NO_OPENGL case OpenGLPBufferType: { QGLPixelBuffer pbuffer(QSize(width, height)); QPainter pt(&pbuffer); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); QImage image = pbuffer.toImage(); QLabel *label = createLabel(); label->setPixmap(QPixmap::fromImage(image)); label->resize(label->sizeHint()); label->show(); activeWidget = label; break; } case OpenGLType: { OnScreenWidget<QGLWidget> *qGLWidget = new OnScreenWidget<QGLWidget>; qGLWidget->setVerboseMode(verboseMode); qGLWidget->setType(type); qGLWidget->setCheckersBackground(checkers_background); qGLWidget->m_filename = files.at(j); qGLWidget->setWindowTitle(fileinfo.filePath()); qGLWidget->m_commands = content; qGLWidget->resize(width, height); qGLWidget->show(); activeWidget = qGLWidget; break; } #else case OpenGLType: printf("OpenGL type not supported in this Qt build\n"); break; #endif #ifdef USE_CUSTOM_DEVICE case CustomDeviceType: { CustomPaintDevice custom(width, height); QPainter pt; pt.begin(&custom); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); QImage *img = custom.image(); if (img) { QLabel *label = createLabel(); label->setPixmap(QPixmap::fromImage(*img)); label->resize(label->sizeHint()); label->show(); activeWidget = label; img->save("custom_output_pixmap.png", "PNG"); } else { custom.save("custom_output_pixmap.png", "PNG"); } break; } case CustomWidgetType: { OnScreenWidget<CustomWidget> *cWidget = new OnScreenWidget<CustomWidget>; cWidget->setVerboseMode(verboseMode); cWidget->setType(type); cWidget->setCheckersBackground(checkers_background); cWidget->m_filename = files.at(j); cWidget->setWindowTitle(fileinfo.filePath()); cWidget->m_commands = content; cWidget->resize(width, height); cWidget->show(); activeWidget = cWidget; break; } #endif case PixmapType: { QPixmap pixmap(width, height); pixmap.fill(Qt::white); QPainter pt(&pixmap); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); pixmap.save("output_pixmap.png", "PNG"); break; } case BitmapType: { QBitmap bitmap(width, height); QPainter pt(&bitmap); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); bitmap.save("output_bitmap.png", "PNG"); QLabel *label = createLabel(); label->setPixmap(bitmap); label->resize(label->sizeHint()); label->show(); activeWidget = label; break; } case ImageMonoType: case ImageType: { qDebug() << "Creating image"; QImage image(width, height, type == ImageMonoType ? QImage::Format_MonoLSB : imageFormat); image.fill(0); QPainter pt(&image); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); image.convertToFormat(QImage::Format_ARGB32).save("output_image.png", "PNG"); #ifndef CONSOLE_APPLICATION QLabel *label = createLabel(); label->setPixmap(QPixmap::fromImage(image)); label->resize(label->sizeHint()); label->show(); activeWidget = label; #endif break; } case PictureType: { QPicture pic; QPainter pt(&pic); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); QImage image(width, height, QImage::Format_ARGB32_Premultiplied); image.fill(0); pt.begin(&image); pt.drawPicture(0, 0, pic); pt.end(); QLabel *label = createLabel(); label->setWindowTitle(fileinfo.absolutePath()); label->setPixmap(QPixmap::fromImage(image)); label->resize(label->sizeHint()); label->show(); activeWidget = label; break; } case PrinterType: { PaintCommands pcmd(QStringList(), 800, 800); pcmd.setVerboseMode(verboseMode); pcmd.setType(type); pcmd.setCheckersBackground(checkers_background); pcmd.setContents(content); QString file = QString(files.at(j)).replace(".", "_") + ".ps"; QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution); if (printdlg) { QPrintDialog printDialog(&p, 0); if (printDialog.exec() != QDialog::Accepted) break; } else { p.setOutputFileName(file); } QPainter pt(&p); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); if (!printdlg) { printf("wrote file: %s\n", qPrintable(file)); } Q_ASSERT(!p.paintingActive()); break; } case PsType: case PdfType: { PaintCommands pcmd(QStringList(), 800, 800); pcmd.setVerboseMode(verboseMode); pcmd.setType(type); pcmd.setCheckersBackground(checkers_background); pcmd.setContents(content); bool ps = type == PsType; QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution); QFileInfo input(files.at(j)); QString file = QString("%1_%2.%3") .arg(input.baseName()) .arg(input.suffix()) .arg(ps ? "ps" : "pdf"); p.setOutputFormat(ps ? QPrinter::PdfFormat : QPrinter::PostScriptFormat); p.setOutputFileName(file); p.setPageSize(QPrinter::A4); QPainter pt(&p); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); printf("write file: %s\n", qPrintable(file)); break; } case GrabType: { QImage image(width, height, QImage::Format_ARGB32_Premultiplied); image.fill(QColor(Qt::white).rgb()); QPainter pt(&image); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); QImage image1(width, height, QImage::Format_RGB32); image1.fill(QColor(Qt::white).rgb()); QPainter pt1(&image1); pt1.drawImage(QPointF(0, 0), image); pt1.end(); QString filename = QString(files.at(j)).replace(".qps", "_qps") + ".png"; image1.save(filename, "PNG"); printf("%s grabbed to %s\n", qPrintable(files.at(j)), qPrintable(filename)); break; } default: break; } } } #ifndef CONSOLE_APPLICATION if (activeWidget || interactive) { QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); app.exec(); } delete activeWidget; #endif return 0; }
int main() { // image matching // 1. Read input images cv::Mat image1= cv::imread("church01.jpg",CV_LOAD_IMAGE_GRAYSCALE); cv::Mat image2= cv::imread("church02.jpg",CV_LOAD_IMAGE_GRAYSCALE); // 2. Define keypoints vector std::vector<cv::KeyPoint> keypoints1; std::vector<cv::KeyPoint> keypoints2; // 3. Define feature detector cv::FastFeatureDetector fastDet(80); // 4. Keypoint detection fastDet.detect(image1,keypoints1); fastDet.detect(image2,keypoints2); std::cout << "Number of keypoints (image 1): " << keypoints1.size() << std::endl; std::cout << "Number of keypoints (image 2): " << keypoints2.size() << std::endl; // 5. Define a square neighborhood const int nsize(11); // size of the neighborhood cv::Rect neighborhood(0, 0, nsize, nsize); // 11x11 cv::Mat patch1; cv::Mat patch2; // 6. For all keypoints in first image // find best match in second image cv::Mat result; std::vector<cv::DMatch> matches; //for all keypoints in image 1 for (int i=0; i<keypoints1.size(); i++) { // define image patch neighborhood.x = keypoints1[i].pt.x-nsize/2; neighborhood.y = keypoints1[i].pt.y-nsize/2; // if neighborhood of points outside image, then continue with next point if (neighborhood.x<0 || neighborhood.y<0 || neighborhood.x+nsize >= image1.cols || neighborhood.y+nsize >= image1.rows) continue; //patch in image 1 patch1 = image1(neighborhood); // reset best correlation value; cv::DMatch bestMatch; //for all keypoints in image 2 for (int j=0; j<keypoints2.size(); j++) { // define image patch neighborhood.x = keypoints2[j].pt.x-nsize/2; neighborhood.y = keypoints2[j].pt.y-nsize/2; // if neighborhood of points outside image, then continue with next point if (neighborhood.x<0 || neighborhood.y<0 || neighborhood.x + nsize >= image2.cols || neighborhood.y + nsize >= image2.rows) continue; // patch in image 2 patch2 = image2(neighborhood); // match the two patches cv::matchTemplate(patch1,patch2,result,CV_TM_SQDIFF_NORMED); // check if it is a best match if (result.at<float>(0,0) < bestMatch.distance) { bestMatch.distance= result.at<float>(0,0); bestMatch.queryIdx= i; bestMatch.trainIdx= j; } } // add the best match matches.push_back(bestMatch); } std::cout << "Number of matches: " << matches.size() << std::endl; // extract the 50 best matches std::nth_element(matches.begin(),matches.begin()+50,matches.end()); matches.erase(matches.begin()+50,matches.end()); std::cout << "Number of matches (after): " << matches.size() << std::endl; // Draw the matching results cv::Mat matchImage; cv::drawMatches(image1,keypoints1, // first image image2,keypoints2, // second image matches, // vector of matches matchImage, // produced image cv::Scalar(255,255,255), // line color cv::Scalar(255,255,255)); // point color // Display the image of matches cv::namedWindow("Matches"); cv::imshow("Matches",matchImage); // Match template // define a template cv::Mat target(image1,cv::Rect(80,105,30,30)); // Display the template cv::namedWindow("Template"); cv::imshow("Template",target); // define search region cv::Mat roi(image2, // here top half of the image cv::Rect(0,0,image2.cols,image2.rows/2)); // perform template matching cv::matchTemplate( roi, // search region target, // template result, // result CV_TM_SQDIFF); // similarity measure // find most similar location double minVal, maxVal; cv::Point minPt, maxPt; cv::minMaxLoc(result, &minVal, &maxVal, &minPt, &maxPt); // draw rectangle at most similar location // at minPt in this case cv::rectangle(roi, cv::Rect(minPt.x, minPt.y, target.cols , target.rows), 255); // Display the template cv::namedWindow("Best"); cv::imshow("Best",image2); cv::waitKey(); return 0; }
void WindowTexture::generateWindowTexture() //randomly generate windows texture for buildings { CBitmap image0("building/texture/1.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[0]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image0.GetWidth(),image0.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image0.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image1("building/texture/2.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[1]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image1.GetWidth(),image1.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image1.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image2("building/texture/3.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[2]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image2.GetWidth(),image2.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image2.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image3("building/texture/4.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[3]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image3.GetWidth(),image3.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image3.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image4("building/texture/5.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[4]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image4.GetWidth(),image4.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image4.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); CBitmap image100("building/texture/mailbox_asdf.bmp"); glBindTexture(GL_TEXTURE_2D, m_nTextureId[numTex]); //bind this texture to be active glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image100.GetWidth(),image100.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,image100.GetBits()); //load data into texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //specify minificaton filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //specify magnificaton filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //specify texture coordinate treatment glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //specify texture coordinate treatment glEnable(GL_TEXTURE_2D); textureBounded = true; }
/* * Constructs a Smilies which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ Smilies::Smilies( QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ) { QPixmap image0( SmallIcon("face_smile") ); QPixmap image1( SmallIcon("face_angel") ); QPixmap image2( SmallIcon("face_embarrassed") ); QPixmap image3( SmallIcon("face_yell") ); QPixmap image4( SmallIcon("face_wink") ); QPixmap image5( SmallIcon("face_glasses") ); QPixmap image6( SmallIcon("face_moneymouth") ); QPixmap image7( SmallIcon("face_crossedlips") ); QPixmap image8( SmallIcon("face_sad") ); QPixmap image9( SmallIcon("face_scream") ); QPixmap image10( SmallIcon("face_cry") ); QPixmap image11( SmallIcon("face_burp") ); QPixmap image12( SmallIcon("face_kiss") ); QPixmap image13( SmallIcon("face_think") ); QPixmap image14( SmallIcon("face_tongue") ); QPixmap image15( SmallIcon("face_luke") ); QPixmap image16( SmallIcon("face_bigsmile") ); QPixmap image17( SmallIcon("face_oneeye") ); if ( !name ) setName( "Smilies" ); resize( 124, 139 ); setCaption( tr( "kaim-smiles" ) ); SmiliesLayout = new QGridLayout( this ); SmiliesLayout->setSpacing( 0 ); SmiliesLayout->setMargin( 0 ); smile = new QToolButton( this, "smile" ); smile->setText( tr( " " ) ); smile->setPixmap( image0 ); SmiliesLayout->addWidget( smile, 0, 0 ); angel = new QToolButton( this, "angel" ); angel->setText( tr( " " ) ); angel->setPixmap( image1 ); SmiliesLayout->addWidget( angel, 2, 3 ); embarrassed = new QToolButton( this, "embarrassed" ); embarrassed->setText( tr( " " ) ); embarrassed->setPixmap( image2 ); SmiliesLayout->addWidget( embarrassed, 2, 2 ); yell = new QToolButton( this, "yell" ); yell->setText( tr( " " ) ); yell->setPixmap( image3 ); SmiliesLayout->addWidget( yell, 1, 2 ); wink = new QToolButton( this, "wink" ); wink->setText( tr( " " ) ); wink->setPixmap( image4 ); SmiliesLayout->addWidget( wink, 0, 3 ); glasses = new QToolButton( this, "glasses" ); glasses->setText( tr( " " ) ); glasses->setPixmap( image5 ); SmiliesLayout->addWidget( glasses, 2, 0 ); moneymouth = new QToolButton( this, "moneymouth" ); moneymouth->setText( tr( " " ) ); moneymouth->setPixmap( image6 ); SmiliesLayout->addWidget( moneymouth, 3, 3 ); crossedlips = new QToolButton( this, "crossedlips" ); crossedlips->setText( tr( " " ) ); crossedlips->setPixmap( image7 ); SmiliesLayout->addWidget( crossedlips, 3, 2 ); sad = new QToolButton( this, "sad" ); sad->setText( tr( " " ) ); sad->setPixmap( image8 ); SmiliesLayout->addWidget( sad, 0, 2 ); scream = new QToolButton( this, "scream" ); scream->setText( tr( " " ) ); scream->setPixmap( image9 ); SmiliesLayout->addWidget( scream, 1, 1 ); cry = new QToolButton( this, "cry" ); cry->setText( tr( " " ) ); cry->setPixmap( image10 ); SmiliesLayout->addWidget( cry, 3, 1 ); burp = new QToolButton( this, "burp" ); burp->setText( tr( " " ) ); burp->setPixmap( image11 ); SmiliesLayout->addWidget( burp, 2, 1 ); kiss = new QToolButton( this, "kiss" ); kiss->setText( tr( " " ) ); kiss->setPixmap( image12 ); SmiliesLayout->addWidget( kiss, 1, 3 ); think = new QToolButton( this, "think" ); think->setText( tr( " " ) ); think->setPixmap( image13 ); SmiliesLayout->addWidget( think, 3, 0 ); tongue = new QToolButton( this, "tongue" ); tongue->setText( tr( " " ) ); tongue->setPixmap( image14 ); SmiliesLayout->addWidget( tongue, 1, 0 ); luke = new QToolButton( this, "luke" ); luke->setText( tr( " " ) ); luke->setPixmap( image15 ); SmiliesLayout->addWidget( luke, 4, 2 ); bigsmile = new QToolButton( this, "bigsmile" ); bigsmile->setText( tr( " " ) ); bigsmile->setPixmap( image16 ); SmiliesLayout->addWidget( bigsmile, 0, 1 ); oneeye = new QToolButton( this, "oneeye" ); oneeye->setText( tr( " " ) ); oneeye->setPixmap( image17 ); SmiliesLayout->addWidget( oneeye, 4, 1 ); QObject::connect( smile, SIGNAL(clicked()), SLOT(smileClicked()) ); QObject::connect( angel, SIGNAL(clicked()), SLOT(angelClicked()) ); QObject::connect( embarrassed, SIGNAL(clicked()), SLOT(embarrassedClicked()) ); QObject::connect( yell, SIGNAL(clicked()), SLOT(yellClicked()) ); QObject::connect( wink, SIGNAL(clicked()), SLOT(winkClicked()) ); QObject::connect( glasses, SIGNAL(clicked()), SLOT(glassesClicked()) ); QObject::connect( moneymouth, SIGNAL(clicked()), SLOT(moneymouthClicked()) ); QObject::connect( crossedlips, SIGNAL(clicked()), SLOT(crossedlipsClicked()) ); QObject::connect( sad, SIGNAL(clicked()), SLOT(sadClicked()) ); QObject::connect( scream, SIGNAL(clicked()), SLOT(screamClicked()) ); QObject::connect( cry, SIGNAL(clicked()), SLOT(cryClicked()) ); QObject::connect( burp, SIGNAL(clicked()), SLOT(burpClicked()) ); QObject::connect( kiss, SIGNAL(clicked()), SLOT(kissClicked()) ); QObject::connect( think, SIGNAL(clicked()), SLOT(thinkClicked()) ); QObject::connect( tongue, SIGNAL(clicked()), SLOT(tongueClicked()) ); QObject::connect( luke, SIGNAL(clicked()), SLOT(lukeClicked()) ); QObject::connect( bigsmile, SIGNAL(clicked()), SLOT(bigsmileClicked()) ); QObject::connect( oneeye, SIGNAL(clicked()), SLOT(oneeyeClicked()) ); }
void prob3b(){ // filenames std::string train1 = "Data_Prog2/Training_1.ppm"; std::string ref1 = "Data_Prog2/ref1.ppm"; // variable declarations int M, N, Q; bool type; // make image objects readImageHeader(train1.c_str(), N, M, Q, type); ImageType image1(N, M, Q); ImageType refimage1(N, M, Q); readImage(train1.c_str(),image1); readImage(ref1.c_str(),refimage1); // make skin colors Matrix skin_colors, non_skin_colors; makeColorMatrices(image1, refimage1, skin_colors, non_skin_colors, true); // estimate parameters for skin-color class std::vector<double> mean1 = getSampleMean(skin_colors); std::cout << "sample_mean1 = "; print_vec(mean1); Matrix cov1 = getSampleVar(skin_colors, mean1); std::cout << "sample_cov1 = "; print_matrix(cov1); // set up parameters for non-skin-color class std::vector<double> mean2 = getSampleMean(non_skin_colors); Matrix cov2 = getSampleVar(non_skin_colors, mean2); std::cout << "sample_mean2 = "; print_vec(mean2); std::cout << "sample_cov2 = "; print_matrix(cov2); // make classifier QuadraticDiscriminant classifier(mean1, mean2, cov1, cov2, 0.08, 0.92); std::string out1 = "Data_Prog2/out1b.ppm"; testSkinRecognition(classifier, image1, refimage1, out1, true); std::string train3 = "Data_Prog2/Training_3.ppm"; std::string ref3 = "Data_Prog2/ref3.ppm"; readImageHeader(train3.c_str(), N, M, Q, type); ImageType image3(N, M, Q); ImageType refimage3(N, M, Q); readImage(train3.c_str(),image3); readImage(ref3.c_str(),refimage3); std::string out3 = "Data_Prog2/out3b.ppm"; testSkinRecognition(classifier, image3, refimage3, out3, true); std::string train6 = "Data_Prog2/Training_6.ppm"; std::string ref6 = "Data_Prog2/ref6.ppm"; readImageHeader(train6.c_str(), N, M, Q, type); ImageType image6(N, M, Q); ImageType refimage6(N, M, Q); readImage(train6.c_str(),image6); readImage(ref6.c_str(),refimage6); std::string out6 = "Data_Prog2/out6b.ppm"; testSkinRecognition(classifier, image6, refimage6, out6, true); }
void MainWindow::CreateLayout() { layout = new QHBoxLayout; QHBoxLayout* leftLayout = new QHBoxLayout; leftLayout->setContentsMargins(10, 0, 10, 0); leftLayout->setSpacing(20); gxin = new ClickedLabel(20); gxin->setText("<u>更新</u>"); connect(gxin,SIGNAL(clicked()),this,SLOT(OnGengxin())); wluo = new ClickedLabel(20); wluo->setText("<u>网络</u>"); wluo->setDisabled(true); wjian = new ClickedLabel(20); wjian->setText("<u>文件</u>"); connect(wjian, SIGNAL(clicked()),this, SLOT(OnWenjian())); bbiao = new ClickedLabel(20); bbiao->setText("<u>报表</u>"); connect(bbiao,SIGNAL(clicked()),this,SLOT(OnBaobiao())); fwuqi = new ClickedLabel(20); fwuqi->setVisible(false); fwuqi->setText("<u>服务器</u>"); connect(fwuqi,SIGNAL(clicked()),this,SLOT(OnJiaoZhun())); cangkuid = new QLabel; cangkuid->setText("仓库ID:"); devDB devDB; string cid; devDB.get(CHAN_ID, cid); id = new QLabel; id->setText(QString::fromStdString(cid)); //更新图标 LabUpdateState = new QLabel; LabUpdateState->setVisible(false); MvUpdate = new QMovie(":/images/updating.gif"); LabUpdateState->setMovie(MvUpdate); //connect(this,SIGNAL(setMvState()),MvUpdate,SLOT(ChangeMvState())); network = new QLabel; //if(m_netConf->isOnline()) if(Global::s_netState) { QImage image1(":/images/NetConn24.ico"); network->setPixmap(QPixmap::fromImage(image1)); } else { QImage image1(":/images/NetDisConn24.ico"); network->setPixmap(QPixmap::fromImage(image1)); } //neicun = new QLabel; //QImage CardImage(":/images/SdCard24.ico"); //neicun->setPixmap(QPixmap::fromImage(CardImage)); shangchuan = new QPushButton; shangchuan->setText("上传"); connect(shangchuan,SIGNAL(clicked()),this,SLOT(OnShangchuan())); weishangchuan = new QLabel; weishangchuan->setText("未上传:"); wscnum = new QLabel; wscnum->setText("0"); QSpacerItem* horizonSpacer1 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); QSpacerItem* horizonSpacer2 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); leftLayout->addWidget(gxin); leftLayout->addWidget(wluo); leftLayout->addWidget(wjian); leftLayout->addWidget(bbiao); layout->addLayout(leftLayout); layout->addSpacerItem(horizonSpacer1); layout->addWidget(cangkuid); layout->addWidget(id); layout->addSpacerItem(horizonSpacer2); layout->addWidget(network); //layout->addWidget(neicun); layout->addWidget(shangchuan); layout->addWidget(weishangchuan); layout->addWidget(wscnum); //layout->addWidget(LabUpdateState); gridlayout = new QGridLayout; for(int nDevCount = 0; nDevCount < DEVCOUNT; nDevCount++) { DevWdg* TmpDevWdg = new DevWdg; s_devArray[nDevCount] = TmpDevWdg; //VecDev.append(TmpDevWdg); QString strNum = QString::number((nDevCount+1),10); s_devArray[nDevCount]->SetNum(strNum); s_devArray[nDevCount]->SetStatus(tr("空闲")); gridlayout->addWidget(s_devArray[nDevCount],nDevCount/6,nDevCount%6); } }