📄 siftfeat.c
字号:
/* This program detects image features using SIFT keypoints. For more info, refer to: Lowe, D. Distinctive image features from scale-invariant keypoints. International Journal of Computer Vision, 60, 2 (2004), pp.91--110. Copyright (C) 2006-2007 Rob Hess <hess@eecs.oregonstate.edu> Note: The SIFT algorithm is patented in the United States and cannot be used in commercial products without a license from the University of British Columbia. For more information, refer to the file LICENSE.ubc that accompanied this distribution. Version: 1.1.1-20070913*/#include "sift.h"#include "imgfeatures.h"#include "utils.h"#include <highgui.h>#include <unistd.h>#define OPTIONS ":o:m:i:s:c:r:n:b:dxh"/*************************** Function Prototypes *****************************/void usage( char* );void arg_parse( int, char** );/******************************** Globals ************************************/char* pname;char* img_file_name;char* out_file_name = NULL;char* out_img_name = NULL;int intvls = SIFT_INTVLS;double sigma = SIFT_SIGMA;double contr_thr = SIFT_CONTR_THR;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;int display = 1;/********************************** Main *************************************/int main( 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 ); return 0;}/************************** Function Definitions *****************************/// print usage for this programvoid usage( char* name ){ fprintf(stderr, "%s: detect SIFT keypoints in an image\n\n", name); fprintf(stderr, "Usage: %s [options] <img_file>\n", name); fprintf(stderr, "Options:\n"); fprintf(stderr, " -h Display this message and exit\n"); fprintf(stderr, " -o <out_file> Output keypoints to text file\n"); fprintf(stderr, " -m <out_img> Output keypoint image file (format" \ " determined by extension)\n"); fprintf(stderr, " -i <intervals> Set number of sampled intervals per" \ " octave in scale space\n"); fprintf(stderr, " pyramid (default %d)\n", SIFT_INTVLS); fprintf(stderr, " -s <sigma> Set sigma for initial gaussian" \ " smoothing at each octave\n"); fprintf(stderr, " (default %06.4f)\n", SIFT_SIGMA); fprintf(stderr, " -c <thresh> Set threshold on keypoint contrast" \ " |D(x)| based on [0,1]\n"); fprintf(stderr, " pixel values (default %06.4f)\n", SIFT_CONTR_THR); fprintf(stderr, " -r <thresh> Set threshold on keypoint ratio of" \ " principle curvatures\n"); fprintf(stderr, " (default %d)\n", SIFT_CURV_THR); fprintf(stderr, " -n <width> Set width of descriptor histogram" \ " array (default %d)\n", SIFT_DESCR_WIDTH); fprintf(stderr, " -b <bins> Set number of bins per histogram" \ " in descriptor array\n"); fprintf(stderr, " (default %d)\n", SIFT_DESCR_HIST_BINS); fprintf(stderr, " -d Toggle image doubling (default %s)\n", SIFT_IMG_DBL == 0 ? "off" : "on"); fprintf(stderr, " -x Turn off keypoint display\n");}/* arg_parse() parses the command line arguments, setting appropriate globals. argc and argv should be passed directly from the command line*/void arg_parse( int argc, char** argv ){ //extract program name from command line (remove path, if present) pname = basename( argv[0] ); //parse commandline options while( 1 ) { char* arg_check; int arg = getopt( argc, argv, OPTIONS ); if( arg == -1 ) break; switch( arg ) { // catch unsupplied required arguments and exit case ':': fatal_error( "-%c option requires an argument\n" \ "Try '%s -h' for help.", optopt, pname ); break; // read out_file_name case 'o': if( ! optarg ) fatal_error( "error parsing arguments at -%c\n" \ "Try '%s -h' for help.", arg, pname ); out_file_name = optarg; break; // read out_img_name case 'm': if( ! optarg ) fatal_error( "error parsing arguments at -%c\n" \ "Try '%s -h' for help.", arg, pname ); out_img_name = optarg; break; // read intervals case 'i': // ensure argument provided if( ! optarg ) fatal_error( "error parsing arguments at -%c\n" \ "Try '%s -h' for help.", arg, pname ); // parse argument and ensure it is an integer intvls = strtol( optarg, &arg_check, 10 ); if( arg_check == optarg || *arg_check != '\0' ) fatal_error( "-%c option requires an integer argument\n" \ "Try '%s -h' for help.", arg, pname ); break; // read sigma case 's' : // ensure argument provided if( ! optarg ) fatal_error( "error parsing arguments at -%c\n" \ "Try '%s -h' for help.", arg, pname ); // parse argument and ensure it is a floating point number sigma = strtod( optarg, &arg_check ); if( arg_check == optarg || *arg_check != '\0' ) fatal_error( "-%c option requires a floating point argument\n" \ "Try '%s -h' for help.", arg, pname ); break; // read contrast_thresh case 'c' : // ensure argument provided if( ! optarg ) fatal_error( "error parsing arguments at -%c\n" \ "Try '%s -h' for help.", arg, pname ); // parse argument and ensure it is a floating point number contr_thr = strtod( optarg, &arg_check ); if( arg_check == optarg || *arg_check != '\0' ) fatal_error( "-%c option requires a floating point argument\n" \ "Try '%s -h' for help.", arg, pname ); break; // read curvature_thresh case 'r' : // ensure argument provided if( ! optarg ) fatal_error( "error parsing arguments at -%c\n" \ "Try '%s -h' for help.", arg, pname ); // parse argument and ensure it is a floating point number curv_thr = strtol( optarg, &arg_check, 10 ); if( arg_check == optarg || *arg_check != '\0' ) fatal_error( "-%c option requires an integer argument\n" \ "Try '%s -h' for help.", arg, pname ); break; // read descr_width case 'n' : // ensure argument provided if( ! optarg ) fatal_error( "error parsing arguments at -%c\n" \ "Try '%s -h' for help.", arg, pname ); // parse argument and ensure it is a floating point number descr_width = strtol( optarg, &arg_check, 10 ); if( arg_check == optarg || *arg_check != '\0' ) fatal_error( "-%c option requires an integer argument\n" \ "Try '%s -h' for help.", arg, pname ); break; // read descr_histo_bins case 'b' : // ensure argument provided if( ! optarg ) fatal_error( "error parsing arguments at -%c\n" \ "Try '%s -h' for help.", arg, pname ); // parse argument and ensure it is a floating point number descr_hist_bins = strtol( optarg, &arg_check, 10 ); if( arg_check == optarg || *arg_check != '\0' ) fatal_error( "-%c option requires an integer argument\n" \ "Try '%s -h' for help.", arg, pname ); break; // read double_image case 'd' : img_dbl = ( img_dbl == 1 )? 0 : 1; break; // read display case 'x' : display = 0; break; // user asked for help case 'h': usage( pname ); exit(0); break; // catch invalid arguments default: fatal_error( "-%c: invalid option.\nTry '%s -h' for help.", optopt, pname ); } } // make sure an input file is specified if( argc - optind < 1 ) fatal_error( "no input file specified.\nTry '%s -h' for help.", pname ); // make sure there aren't too many arguments if( argc - optind > 1 ) fatal_error( "too many arguments.\nTry '%s -h' for help.", pname ); // copy image file name from command line argument img_file_name = argv[optind];}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -