1 | initial version |
Use the H matrix to filter out good_matches by calling perspectiveTransform(obj, obj2, H). Loop through obj2 and compare it with scene points, if they are nearly the same (within some Euclidean distance) then increment a counter. At the end if your count is "high" (you define) then the object is most likely in the scene.
2 | No.2 Revision |
Use the H matrix to filter out good_matches by calling perspectiveTransform(obj, obj2, H). Loop through obj2 and compare it with scene points, if they are nearly the same (within some Euclidean distance) then increment a counter. At the end if your count is "high" (you define) then the object is most likely in the scene.
This all assumes your object can be modeled by as a flat planar 2D object.
3 | No.3 Revision |
Use Updated based on Moster's answer. I totally forgot about the H matrix to filter out good_matches by calling perspectiveTransform(obj, obj2, H).
Loop through obj2 and compare it with scene points, if they are nearly the same (within some Euclidean distance) then increment a counter. At the end if your count is "high" (you define) then the object is most likely in the scene.OuputMask.
This all assumes your object can be modeled by as a flat planar 2D object.Modified this line
Mat H = findHomography( obj, scene, CV_RANSAC );
to
vector<char> mask
Mat H = findHomography( obj, scene, CV_RANSAC, 3, mask );
int good_matches = accumulate(mask.begin(), mask.end(), 0);
Threshold on good_matches to determine if you have an object in the scene. You might need to add #include <numeric> for the accumulate function.
Updated based on Moster's answer. I totally forgot about the OuputMask.
Modified this line
Mat H = findHomography( obj, scene, CV_RANSAC );
to
vector<char> vector<uchar> mask
Mat H = findHomography( obj, scene, CV_RANSAC, 3, mask );
int good_matches = accumulate(mask.begin(), mask.end(), 0);
Threshold on good_matches to determine if you have an object in the scene. You might need to add #include <numeric> for the accumulate function.