//特征点检测 void SiftMatch::on_detectButton_clicked() { img1_Feat = cvCloneImage(img1);//复制图1,深拷贝,用来画特征点 img2_Feat = cvCloneImage(img2);//复制图2,深拷贝,用来画特征点 //默认提取的是LOWE格式的SIFT特征点 //提取并显示第1幅图片上的特征点 n1 = sift_features( img1, &feat1 );//检测图1中的SIFT特征点,n1是图1的特征点个数 export_features("feature1.txt",feat1,n1);//将特征向量数据写入到文件 draw_features( img1_Feat, feat1, n1 );//画出特征点 //cvNamedWindow(IMG1_FEAT);//创建窗口 //cvShowImage(IMG1_FEAT,img1_Feat);//显示 QString name1_Feat = name1;//文件名,原文件名加"_Feat" cvSaveImage(name1_Feat.insert( name1_Feat.lastIndexOf(".",-1) , "_Feat").toAscii().data(),img1_Feat);//保存图片 //提取并显示第2幅图片上的特征点 n2 = sift_features( img2, &feat2 );//检测图2中的SIFT特征点,n2是图2的特征点个数 export_features("feature2.txt",feat2,n2);//将特征向量数据写入到文件 draw_features( img2_Feat, feat2, n2 );//画出特征点 //cvNamedWindow(IMG2_FEAT);//创建窗口 //cvShowImage(IMG2_FEAT,img2_Feat);//显示 QString name2_Feat = name2;//文件名,原文件名加"_Feat" cvSaveImage(name2_Feat.insert( name2_Feat.lastIndexOf(".",-1) , "_Feat").toAscii().data(),img2_Feat);//保存图片 ui->detectButton->setEnabled(false);//禁用特征检测按钮 ui->radioButton_horizontal->setEnabled(true);//激活排列方向选择按钮 ui->radioButton_vertical->setEnabled(true); ui->matchButton->setEnabled(true);//激活特征匹配按钮 }
int main( int argc, char** argv ) { IplImage* img; struct feature* features; int n = 0; fprintf( stderr, "Finding SIFT features...\n" ); img = cvLoadImage( img_file_name, 1 ); if( ! img ) { fprintf( stderr, "unable to load image from %s", img_file_name ); exit( 1 ); } n = _sift_features( img, &features, intvls, sigma, contr_thr, curv_thr, img_dbl, descr_width, descr_hist_bins ); fprintf( stderr, "Found %d features.\n", n ); if( display ) { draw_features( img, features, n ); cvNamedWindow( img_file_name, 1 ); cvShowImage( img_file_name, img ); cvWaitKey( 0 ); } if( out_file_name != NULL ) export_features( out_file_name, features, n ); if( out_img_name != NULL ) cvSaveImage( out_img_name, img ); return 0; }
// Feature Thread void* featureThread(void* featureData) { char file[25]; int index, numFeatures; struct feature* feat; struct fData* temp; temp = (struct fData*) featureData; IplImage* img = temp->img; index = temp->index; sprintf(file, "features/temp%d", index); struct feature* feat1; if (import_features(file, FEATURE_LOWE, &feat1) == -1) { numFeatures = sift_features(img, &feat); export_features(file, feat, numFeatures); printf("features for image %d:\n", index); // print all features if (DEBUG) { printFeature(feat, numFeatures, 100); printf("\n\n"); } } }
int CUtil_Sift::GetSiftFile( const char* imagefile,const char* siftfile ) { int intvls = SIFT_INTVLS; double sigma = SIFT_SIGMA; double contr_thr = 0.2; int curv_thr = SIFT_CURV_THR; int img_dbl = SIFT_IMG_DBL; int descr_width = SIFT_DESCR_WIDTH; int descr_hist_bins = SIFT_DESCR_HIST_BINS; IplImage* img; struct feature* features; int n = 0; if ( !imagefile || !siftfile ) { return -1; } if ( strlen(imagefile)<1 || strlen(siftfile)<1 ) { return -1; } img = cvLoadImage( imagefile,1); if( !img ) { return -1; } fprintf(stderr,"load image %s\n",imagefile); n = _sift_features( img, &features, intvls, sigma, contr_thr, curv_thr, img_dbl, descr_width, descr_hist_bins ); export_features( (char*)siftfile, features, n ); return n; }
int main2( int argc, char** argv ) { IplImage* img; struct feature* features; int n = 0; arg_parse( argc, argv ); fprintf( stderr, "Finding SIFT features...\n" ); img = cvLoadImage( img_file_name, 1 ); if( ! img ) fatal_error( "unable to load image from %s", img_file_name ); n = _sift_features( img, &features, intvls, sigma, contr_thr, curv_thr, img_dbl, descr_width, descr_hist_bins ); fprintf( stderr, "Found %d features.\n", n ); if( display ) { draw_features( img, features, n ); display_big_img( img, img_file_name ); cvWaitKey( 0 ); } if( out_file_name != NULL ) export_features( out_file_name, features, n ); if( out_img_name != NULL ) cvSaveImage( out_img_name, img, NULL ); cvReleaseImage( &img ); return 0; }
// [ref] ${OPENSIFT_HOME}/src/siftfeat.c void extract_feature() { #if 1 const std::string in_img_file_name("./data/feature_analysis/sift/beaver.png"); const std::string out_sift_file_name("./data/feature_analysis/sift/beaver.sift"); const std::string out_img_file_name; #elif 0 const std::string in_img_file_name("./data/feature_analysis/sift/marker_pen_2.bmp"); const std::string out_sift_file_name("./data/feature_analysis/sift/marker_pen_2.sift"); const std::string out_img_file_name; #endif const int display = 1; const int intvls = SIFT_INTVLS; const double sigma = SIFT_SIGMA; const double contr_thr = SIFT_CONTR_THR; const int curv_thr = SIFT_CURV_THR; const int img_dbl = SIFT_IMG_DBL; const int descr_width = SIFT_DESCR_WIDTH; const int descr_hist_bins = SIFT_DESCR_HIST_BINS; std::cout << "finding SIFT features..." << std::endl; IplImage *img = cvLoadImage(in_img_file_name.c_str(), 1); if (!img) { std::cout <<"unable to load image from " << in_img_file_name << std::endl; return; } struct feature *features; const int n = _sift_features(img, &features, intvls, sigma, contr_thr, curv_thr, img_dbl, descr_width, descr_hist_bins); std::cout << "found " << n << " features." << std::endl; if (display) { draw_features(img, features, n); cvNamedWindow(in_img_file_name.c_str(), 1); cvShowImage(in_img_file_name.c_str(), img); cvWaitKey(0); } if (!out_sift_file_name.empty()) export_features((char *)out_sift_file_name.c_str(), features, n); if (!out_img_file_name.empty()) cvSaveImage(out_img_file_name.c_str(), img); }