# findHomography generating an empty matrix

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 close merge delete

Sort by » oldest newest most voted

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...

more

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

more

1

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

( 2015-04-02 08:58:45 -0500 )edit

Official site

GitHub

Wiki

Documentation