1

I am new to openCV. I am trying to follow the OpenCV3.4.0 tutorial on AKAZE and ORB planar tracking tutorial to perform feature matching. I am using the android NDK environment to write c++ code. I managed to get the program to detect features from both the template and the camera pictures, and matched them using the FlannBasedMatcher. The returned matches are stored in the "matched1" and "matched2" array.

How can I get the keypoints stored in matche1 and match2 out? The tutorial suggest to use the function: Points(matched1), which is not available in my coding environment. I checked that I have included all the header files in the tutorial.

Mat& mScene= *(Mat *) scene;
Mat& mTempl = *(Mat *) templ;

vector<Point2f> object_bb;
Mat  descriptorsTemplate,descriptorsCamera;
vector<KeyPoint> keypointsTemplate,keypointsCamera;
Ptr<ORB> fd_de = ORB::create();
fd_de->detectAndCompute( mScene, Mat(), keypointsCamera, 
  descriptorsCamera);
fd_de->detectAndCompute( mTempl, Mat(), keypointsTemplate, 
  descriptorsTemplate );
Mat img_keypoints_1,img_keypoints_2;

cv::FlannBasedMatcher matcher = 
cv::FlannBasedMatcher(cv::makePtr<cv::flann::LshIndexParams>(12, 20, 
   2));

vector< vector<DMatch> > matches;
vector<KeyPoint> matched1, matched2;
matcher.knnMatch(descriptorsTemplate, descriptorsCamera, matches,2);

for( int i = 0; i < matches.size(); i++ ){
     if(matches[i][0].distance < nn_match_ratio * matches[i]
        [1].distance) {
        matched1.push_back(keypointsTemplate[matches[i][0].queryIdx]);
        matched2.push_back(keypointsCamera[matches[i][0].trainIdx]);
    }

}

Mat inlier_mask, homography;
vector<KeyPoint> inliers1, inliers2;
vector<DMatch> inlier_matches;
if(matched1.size() >= 4) {
     homography = findHomography(Points(matched1), Points(matched2),
                                 RANSAC, ransac_thresh, inlier_mask);
}

1 Answers1

0

The Points function can be found in utils.h - remember to import it.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Pathum
  • 1
  • 3
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Til Apr 10 '19 at 09:02