コード例 #1
0
ファイル: util_sift.cpp プロジェクト: douzsh/douzsh
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;
}
コード例 #2
0
ファイル: siftfeat.c プロジェクト: Noobidoo/insight3d
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;
}
コード例 #3
0
ファイル: sift.c プロジェクト: githubcjl/uVision_cjl
/**
Finds SIFT features in an image using default parameter values.  All
detected features are stored in the array pointed to by \a feat.

@param img the image in which to detect features
@param feat a pointer to an array in which to store detected features

@return Returns the number of features stored in \a feat or -1 on failure
@see _sift_features()
*/
int sift_features( IplImage* img, struct feature** feat )
{
    //调用_sift_features()函数进行特征点检测
	return _sift_features( img, feat, SIFT_INTVLS, SIFT_SIGMA, SIFT_CONTR_THR,
							SIFT_CURV_THR, SIFT_IMG_DBL, SIFT_DESCR_WIDTH,
							SIFT_DESCR_HIST_BINS );
}
コード例 #4
0
ファイル: siftfeat.c プロジェクト: xiawei0000/Logo_de
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);
}
コード例 #6
0
ファイル: main.c プロジェクト: enkore/siftsearch
/**
 * Apply SIFT algorithm to an image
 *
 * @return 0 on failure, nonzero on success
 */
int sift(const char *path, struct feature **features, int *num_features)
{
    IplImage *img;
    static const int MAX_SIZE = 800;

    img = cvLoadImage(path, CV_LOAD_IMAGE_COLOR);
    if(!img) {
        fprintf(stderr, "%s: I/O error\n", path);
        return 0;
    }

    if(img->width > MAX_SIZE || img->height > MAX_SIZE) {
        IplImage *scaled = cvCreateImage(cvSize(img->width > MAX_SIZE ? MAX_SIZE : img->width,
                                                img->height > MAX_SIZE ? MAX_SIZE : img->height),
                                         img->depth, img->nChannels);

        if(!scaled) {
            fprintf(stderr, "%s: cvCreateImage failed (out of memory?)\n", path);
            cvReleaseImage(&img);
            return 0;
        }

        cvResize(img, scaled, CV_INTER_LINEAR);
        cvReleaseImage(&img);
        img = scaled;
    }

    (*num_features) = _sift_features(img, features, SIFT_INTVLS, SIFT_SIGMA, SIFT_CONTRAST_THRESHOLD,
                                     SIFT_CURV_THR, SIFT_IMG_DBL, SIFT_DESCR_WIDTH,
                                     SIFT_DESCR_HIST_BINS);
    cvReleaseImage(&img);

    if(!(*features) || !(*num_features)) {
        fprintf(stderr, "%s: No features found\n", path);
        return 0;
    }

    return 1;
}
コード例 #7
0
bool BagOfFeatures::extractSIFTFeatures(int lvls = SIFT_INTVLS,
                                        double sigma = SIFT_SIGMA,
                                        double thresh1 = SIFT_CONTR_THR,
                                        int thresh2 = SIFT_CURV_THR,
                                        int dbl = SIFT_IMG_DBL,
                                        int width = SIFT_DESCR_WIDTH,
                                        int bins = SIFT_DESCR_HIST_BINS)
{
    if(numFeatures)
        return false;

	int i, j;
    int train, valid, test, label;
    int count;
    char fileName[256];
    IplImage *dataImage = NULL;
    struct feature *siftFeatures = NULL;

    descrSize = width*width*bins;

    // For each object class
	for(i = 0; i < numClasses; i++)
	{
	    // Get the distribution of data
        data[i].getDataInfo(train, valid, test, label);

        // Extrain the features of the training set
        // For each training image
        for(j = 0; j < train; j++)
        {
            // Get the image from the data list
            strcpy(fileName, data[i].getDataList(j));
            cout << "Loading training image: " << fileName << endl;
            dataImage = cvLoadImage(fileName);
            IplImage *dataGray = cvCreateImage(cvSize(dataImage->width, dataImage->height), 8, 1);
            // Convert to grayscale
            cvCvtColor(dataImage, dataGray, CV_BGR2GRAY);

            IplImage *resized = preProcessImages(dataGray, 80, 200);

            // Extract the sift features from the images
            //Default:  SIFT_INTVLS, SIFT_SIGMA, SIFT_CONTR_THR, SIFT_CURV_THR,
            //          SIFT_IMG_DBL, SIFT_DESCR_WIDTH, SIFT_DESCR_HIST_BINS
            count = _sift_features(resized, &siftFeatures, lvls, sigma, thresh1, thresh2, dbl, width, bins);
            cout << "Found " << count << " SIFT interest points" << endl;

            // Keep a running total of features for training purposes
            numFeatures += count;

            // Copy the descriptors into the feature set
            copySIFTPts(trainObject[i].featureSet[j], siftFeatures, count, descrSize);

            // Release Memory
            free(siftFeatures);
            cvReleaseImage(&dataImage);
            cvReleaseImage(&dataGray);
            cvReleaseImage(&resized);
        }

        // Extrain the features of the validation set
        // For each validation image
        for(j = 0; j < valid; j++)
        {
            // Get the image from the data list
            strcpy(fileName, data[i].getDataList(j+train));
            cout << "Loading validation image: " << fileName << endl;
            dataImage = cvLoadImage(fileName);
            IplImage *dataGray = cvCreateImage(cvSize(dataImage->width, dataImage->height), 8, 1);
            // Convert to grayscale
            cvCvtColor(dataImage, dataGray, CV_BGR2GRAY);

            IplImage *resized = preProcessImages(dataGray, 80, 200);

            // Extract the sift features from the images
            //Default:  SIFT_INTVLS, SIFT_SIGMA, SIFT_CONTR_THR, SIFT_CURV_THR,
            //          SIFT_IMG_DBL, SIFT_DESCR_WIDTH, SIFT_DESCR_HIST_BINS
            count = _sift_features(resized, &siftFeatures, lvls, sigma, thresh1, thresh2, dbl, width, bins);
            cout << "Found " << count << " SIFT interest points" << endl;

            // Copy the descriptors into the feature set
            copySIFTPts(validObject[i].featureSet[j], siftFeatures, count, descrSize);

            // Release Memory
            free(siftFeatures);
            cvReleaseImage(&dataImage);
            cvReleaseImage(&dataGray);
            cvReleaseImage(&resized);
        }

        // Extrain the features of the test set
        // For each test image
        for(j = 0; j < test; j++)
        {
            // Get the image from the data list
            strcpy(fileName, data[i].getDataList(j+train+valid));
            cout << "Loading test image: " << fileName << endl;
            dataImage = cvLoadImage(fileName);
            IplImage *dataGray = cvCreateImage(cvSize(dataImage->width, dataImage->height), 8, 1);
            // Convert to grayscale
            cvCvtColor(dataImage, dataGray, CV_BGR2GRAY);

            IplImage *resized = preProcessImages(dataGray, 80, 200);

            // Extract the sift features from the images
            //Default:  SIFT_INTVLS, SIFT_SIGMA, SIFT_CONTR_THR, SIFT_CURV_THR,
            //          SIFT_IMG_DBL, SIFT_DESCR_WIDTH, SIFT_DESCR_HIST_BINS
            count = _sift_features(resized, &siftFeatures, lvls, sigma, thresh1, thresh2, dbl, width, bins);
            cout << "Found " << count << " SIFT interest points" << endl;

            // Copy the descriptors into the feature set
            copySIFTPts(testObject[i].featureSet[j], siftFeatures, count, descrSize);

            // Release Memory
            free(siftFeatures);
            cvReleaseImage(&dataImage);
            cvReleaseImage(&dataGray);
            cvReleaseImage(&resized);
        }
	}

	return true;
}