Surf and masks

asked 2013-09-10 08:28:02 -0600

abrykt gravatar image

updated 2013-09-10 08:30:01 -0600

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::Mat mask1 = cv::Mat::zeros(mat.size(), mat.type());
 cv::Rect roi1(0, 0, 50, 100);
 cv::Mat selected1(mask1, roi1);  // select a ROI
 selected1 = cv::Scalar(255, 255, 255);
 detector.detect(mat, keypoints_for_roi_1, mask1);

 cv::Mat mask2 = cv::Mat::zeros(mat.size(), mat.type());
 cv::Rect roi2(0, 50, 50, 100);
 cv::Mat selected2(mask2, roi2);  // select a ROI
 selected2 = cv::Scalar(255, 255, 255);
 detector.detect(mat, keypoints_for_roi_2, mask2);

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 flag offensive close merge delete

Comments

I have same problem with ORB features, while using mask to detect keypoints grid by grid. Afterwards, I tried to compute descriptors on whole image, but without success.

GizmoRobotics gravatar imageGizmoRobotics ( 2018-07-21 08:00:05 -0600 )edit