open cv Feature matching using given coordinates

475 views Asked by At

I am feature matching between stereo images using openCv, FAST feature detection and Brute force matching.

            FastFeatureDetector detector(threshold);
            detector.detect(img1, keypoints1);
            detector.detect(img2, keypoints2);

            OrbDescriptorExtractor extractor;
            extractor.compute(img1, keypoints1, descriptors1);
            extractor.compute(img2, keypoints2, descriptors2);

            BFMatcher matcher(NORM_L2);
            matcher.match(descriptors1, descriptors2, matches);

What I would like to do though, Is track points on the left frame using optical flow, THEN match those points on the right frame using feature matching.

Is it possible to feed a feature matching function the pixel coordinates of the point that you wish to match?

1

There are 1 answers

0
xiawi On BEST ANSWER

You can not specify this to the matcher but you can limit the points at extraction time. In your code keypoints1 and keypoints2 can be the inputs of the extractor for the points you wish to match only. Hence, you should do the following:

// perform "optical flow tracking" and get some points
// for left and right frame

// convert them to cv::KeyPoint
// cv::KeyPoint keypoints1; // left frames
// cv::KeyPoint keypoints1; // right frames

// extract feature for those points only
OrbDescriptorExtractor extractor;
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);

// match for the descriptors computed at the pixel coordinates
// given by the "optical flow tracking" only
BFMatcher matcher(NORM_L2);
matcher.match(descriptors1, descriptors2, matches);