I am writing an application that should detect keypoints and compute descriptors for the SURF algorithm. The keypoints and descriptors for various regions in an image should be detected/computed at various stages in the program. For example, if an 100x100 image is processed, the keypoints/descriptors for the region at (0,0) with width 50 and height 100 should be detected at one point, and the region at (50,0) with width 50 and height 100 should be detected at another point.

To detect the keypoints, I use the mask parameter to input a mask which have non zero values in the region where the detection should occur.

 Mat mat = imread( "box.png", CV_LOAD_IMAGE_GRAYSCALE );

SurfFeatureDetector detector;
std::vector<KeyPoint> keypoints_for_roi_1, keypoints_for_roi_2;

cv::Rect roi1(0, 0, 50, 100);
cv::Mat selected1(mask1, roi1);  // select a ROI
selected1 = cv::Scalar(255, 255, 255);

cv::Rect roi2(0, 50, 50, 100);
cv::Mat selected2(mask2, roi2);  // select a ROI
selected2 = cv::Scalar(255, 255, 255);


To compute the descriptors I then pass the whole image along with the detected keypoints.

 SurfDescriptorExtractor extractor;
Mat descriptors_roi_1, descriptors_roi_2;

extractor.compute(mat, keypoints_for_roi_1, descriptors_roi_1);
extractor.compute(mat, keypoints_for_roi_2, descriptors_roi_2);


To check my results, I then detect keypoints and compute descriptors for the same image like this:

Mat mat = imread( "box.png", CV_LOAD_IMAGE_GRAYSCALE );
SurfFeatureDetector detector;
std::vector<KeyPoint> keypoints;
detector.detect(mat, keypoints);
SurfDescriptorExtractor extractor;
Mat descriptors;
extractor.compute(mat, keypoints, descriptors);


I then check so that the keypoints in keypoints_for_roi_1 and keypoints_for_roi_2 are present in kepoints, and they are. So the keypoints are detected correct.

But, when I check so that the descriptors in descriptors_roi_1 and descriptors_roi_2 are present in descriptors, then some of them are but some are not (I check by looping thru the descriptors matrix to find the row which matches)

Does anyone have any idea why the descriptors does not match when compared?

edit retag close merge delete