Coordinates of keypoints using FLANN matcher

asked 2016-06-06 09:50:12 -0600

aripod gravatar image

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.

edit retag flag offensive close merge delete

Comments

"I have two images (faces) and I want to check if it is the same person or not." - this is called "face verification", and imho, you won't get anywhere with your current approach (wrong tool for the job).

keypoint/descriptor matching was made to find similar keypoints in rotated/scaled/distorted versions of the same scene, not to distinguish different objects

have a look here for SOA

berak gravatar imageberak ( 2016-06-06 09:54:06 -0600 )edit

I tried with histogram comparison but I still have better results with keypoints, only if I could check that all the points are in the same Y axis would be enough for my simple application...

aripod gravatar imagearipod ( 2016-06-07 04:11:49 -0600 )edit