Opencv SIFT需要注意的地方

1。提取的sift 描述符是float,所以要访问每一个数据的话

   			for (int r = 0;r<descriptors.rows;r++){
				const float *dpt = descriptors.ptr<float>(r);
				for(int c = 0;c<descriptors.cols;c++){
					ftrain<<(dpt[c]);
					if(c<descriptors.cols-1)
						ftrain<<" ";
					else
						ftrain<<std::endl;
				}
			}

2.保存数据到txt时最好用" " 而不是std::ends;

3.提取sift特征的代码
1)

	Mat mask;
    int _nfeatures=0;
    int _nOctaveLayers=3;
    double _contrastThreshold=0.04;
    double _edgeThreshold=10;
    double _sigma=1.6;
    SIFT sift(_nfeatures,_nOctaveLayers,_contrastThreshold,_edgeThreshold,
        _sigma);
//    vector<KeyPoint> keypoints;
    bool useProvidedKeypoints=false;
   // Mat descriptors;
    sift(image, mask, keypoints, descriptors, useProvidedKeypoints);

2)

		SiftFeatureDetector detector;
		SiftDescriptorExtractor extractor;
		detector.detect(image,keypoints);
		extractor.compute(image,keypoints,descriptors);




你可能感兴趣的:(Opencv SIFT需要注意的地方)