Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Coordinates of keypoints using FLANN matcher

I have two images (faces) and I want to check if it is the same person or not. So far I implemented as it is in this tutorial and I obtained this results:

image description image description

So far I could work with that. I would just need to check that each point from left and right are in the same horizontal lines I could same it is the same face in both images. But the thing is, how do I get the coordinates of each of the points shown in the images above?

This is the code:

    // Step 1: Detect the keypoints using SURF detect.
    int minHessian = 400;
    SurfFeatureDetector detector(minHessian);
    std::vector<KeyPoint> keypoints_1, keypoints_2;
    detector.detect(roiFrameMaster, keypoints_1);
    detector.detect(roiFrameSlave, keypoints_2);

    // Step 2: Calculate descriptors (feature vectors).
    SurfDescriptorExtractor extractor;
    Mat descriptors_1, descriptors_2;
    extractor.compute(roiFrameMaster, keypoints_1, descriptors_1);
    extractor.compute(roiFrameSlave, keypoints_2, descriptors_2);

    // Step 3 : Matching descriptor vectors using FLANN matcher.
    FlannBasedMatcher matcher;
    std::vector< DMatch > matches;
    matcher.match(descriptors_1, descriptors_2, matches);

    double max_dist = 0; double min_dist = 100;
    //-- Quick calculation of max and min distances between keypoints
    for( int i = 0; i < descriptors_1.rows; i++ )
        double dist = matches[i].distance;
        if(dist < min_dist)
            min_dist = dist;
        if(dist > max_dist)
            max_dist = dist;
    printf("-- Max dist : %f \n", max_dist );
    printf("-- Min dist : %f \n", min_dist );

  //-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist,
  //-- or a small arbitary value ( 0.02 ) in the event that min_dist is very
  //-- small)
  std::vector< DMatch > good_matches;

  for( int i = 0; i < descriptors_1.rows; i++ )
    if( matches[i].distance <= max(2*min_dist, 0.02))
        good_matches.push_back( matches[i]);

  //-- Draw only "good" matches
  Mat img_matches;
  drawMatches(roiFrameMaster, keypoints_1, roiFrameSlave, keypoints_2,
               good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
               vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

  //-- Show detected matches
  imshow( "Good Matches", img_matches);

Thanks for the help.