0

I a trying to make features matching using SIFT algorithm. as shown in figure 1 below, there are matched features betwee the object/query and the scene/train, and i receive the number of good matches equals 8

i repeated the same matching procedure to match the same object/query to absolutely different scene which does not contain the object/query image at all as shown in figure 2. the good matches from that process is 10 good matches. and i am wondering, since the the object i am looking for does not exist at all in the scene why i am getting good matches results?!

what i want to get as a result is, zero matches if the object does not exist in the scene in the scene

how can i achieve that?

update:

do you think using knnMatch could solve that issue?

enter image description here enter image description here

Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • Unless there's an error in your code (I can't know for sure unless you post it), I would say this is just a limitation of today's pattern recognition algorithms. – Sam Estep Jun 28 '15 at 11:27
  • @RedRoboHood isnt there any criteria to indicate whether the object iam lookingg for is found in the scene? because as you see both images contains matches – Amrmsmb Jun 28 '15 at 11:35
  • I'm not sure I understand. If you already know the object you're looking for is not found in the scene, why do you need to run the pattern recognition algorithm at all? Are you using it as a learning algorithm? – Sam Estep Jun 28 '15 at 11:36
  • @RedRoboHood yes it is somthing like that "learning algorithm"..i am detecting some features of interest in frames retrieved from camera, then i am trying to match these features of interests to the scenes captured from the next frames – Amrmsmb Jun 28 '15 at 11:45
  • @RedRoboHood do you think using knnMatch could solve that issue? – Amrmsmb Jun 28 '15 at 11:59
  • how do you decide whether it is a "good match" or just "the best found match"? – Micka Jun 28 '15 at 12:05
  • @RedRoboHood based on thresholding the distances..i sorted the mat"rawMatches" returned from the .match method ascendingly based on the distances, then i picked the first distance "the shortest" the i set a thresold so that, if (distances in the rawmatches mat <= thresold*shrtest distance) then add this point to goodMatchesList – Amrmsmb Jun 28 '15 at 12:12
  • 2
    you should check whether there exists a homography that verifies your good matches. – Micka Jun 28 '15 at 12:30
  • @Micka fine, but i still have another questio please, as far as i know, homography is to surround the detected object in the scene with a rectangle for an exmple. i think if the scene does not containi the object i am lookig for, in any where in the scen there will be drawn any shape...so my question is, if i used homography and perspectiveTransformation how can i check if the shpe dran in the scene encompasses the object i am looking for? – Amrmsmb Jun 28 '15 at 13:00
  • 2
    You should probably be directing your comments at @Micka instead of me. – Sam Estep Jun 28 '15 at 13:01
  • you can create the homography from 4 point correspondences. If they belong to the searched object, the other 6 points should be mapped by the same homography to their matched points but to somewhere further away if not – Micka Jun 28 '15 at 13:19
  • @Micka how can i check if they belon to the searched object or not please? and in your previous comment you said "he other 6 points should be mapped by the same homography "..i thought they are 4 points in total – Amrmsmb Jun 28 '15 at 13:26
  • in your example you have 10 good matches. create a homography from 4 of them and test the same homography for the other 6 (or use all 10 to compute the homography with a RANSAC method and count the inlier). to test a match-pair with a given homography you multiply the point with the homography and test the result's distance to the matched point. – Micka Jun 28 '15 at 13:56

1 Answers1

2

You have matches because there are some descriptors that are similar enough. To be more robust for instance to object detection, you must add a step of geometric consistency checking. Given the sets of points defined e.g as

cv::Mat query_pts(nbMatches, 1, CV_32FC2)
cv::Mat train_pts(nbMatches, 1, CV_32FC2);

You can for instance try to estimate an homography with RANSAC:

H12 = cv::findHomography( query_pts, train_pts, CV_RANSAC, thresh);

Then you check whether the homography has been estimated or not with

if(H12.empty()) cout << "-- Cannot estimate homography" << endl;
xiawi
  • 1,772
  • 4
  • 19
  • 21