Ask Your Question
0

findHomography generating an empty matrix

asked 2015-02-04 14:37:43 -0600

Doombot gravatar image

updated 2015-02-04 21:26:30 -0600

When using findHomography():

Mat H = findHomography( obj, scene, cv::RANSAC , 3, hom_mask, 2000, 0.995 );

sometime, for some image, the resulting H matrix stays empty (H is a UINT8, 1x0x0). However, there is clearly a match between both images (and it looks like good keypoint matches are detected), and just a moment before, with two similar images with similar keypoint responses, a relevant matrix was generated. Input parameters "obj" and "scene" are both a vector of Point2f containing various coordinates.

Is this a common issue? Or do you think a bug might lurk somewhere? Personally, I have processed hundreds of images where a match exists and while I have seen sometime poor matches, it is the first time I get an empty matrix...

EDIT : This said, even if my eyes think that there should be a match in the image pairs, I realize that it might confuses some portion of the image with an other one and that maybe there is indeed no "good" match.

So my question would be: How does findHomography() behave when it is unable to find a suitable Homography? Does it return an empty matrix or will it always give a homography, albeit a very poor one? I just want to know if I encounter standard behaviour or if there is a bug in my own code.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2015-02-05 08:13:08 -0600

Doombot gravatar image

I asked the question on another site and someone had a good answer I think so here is a quick summary:

There is a bug report about using RANSAC or Least Median with findhomography() in OpenCV3. It seems to be common that it returns an empty matrix sometime. According to the bug report, it is likely related to a "new" implementation of Levenberg-Marquardt solver.

Meanwhile, I had already implemented the quick fix suggested by the author of the answer on the other site, namely checking if the matrix is empty after using findHomography() then taking appropriate action.

So that's it for now, I'll probably look for another implementation of the solver, maybe the one used in OpenCV 2.4.9-10...

edit flag offensive delete link more
1

answered 2015-04-01 16:19:16 -0600

Potato gravatar image

I was having the same problem as you did. According to the documentation, "Note that whenever an H matrix cannot be estimated, an empty one will be returned".

-->http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#findhomography

edit flag offensive delete link more

Comments

1

Wow! I read this doc a couple of times and missed that! +1

Doombot gravatar imageDoombot ( 2015-04-02 08:58:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-02-04 14:37:43 -0600

Seen: 3,078 times

Last updated: Apr 01 '15