Detecting garbage homographies from findHomography in opencv?

I’m using findHomography on a list of points and sending the result to warpPerspective.

The problem is that sometimes the result is complete garbage and the resulting image is represented by weird gray rectangles.

How can I detect when findHomography sends me bad results?

opencv sift algorithm, how to get confidence from findHomography

I am trying to create an application for iPhone, but I am a new developer for both openCV and iOS. I have more than 50 object images, I have one scene image from camera. In each time I have one of the

OpenCV c++ findHomography mask values meaning

I am using the function findHomography of OpenCV with the RANSAC method in order to find the homography that relates two images linked with a set of keypoints. Main issue is that I haven’t been able t

OpenCV findHomography Issue

I am working on a Panography / Panorama application in OpenCV and I’ve run into a problem I really can’t figure out. For an idea of what a panorama photograph looks like, have a look here at the Panog

OpenCV cv::findHomography runtime error

I am using to compile and run code from Features2D + Homography to find a known object tutorial, and I am getting this OpenCV Error: Assertion failed (npoints >= 0 && points2.checkVector(2)

calculating the destination points for OpenCV’s findHomography

EDIT: I’ve now found this similar question with a very detailed answer: proportions of a perspective-deformed rectangle I’m using OpenCV’s findHomography() and warpPerspective() methods to de skew a

findHomography, getPerspectiveTransform, & getAffineTransform

This question is on the OpenCV functions findHomography, getPerspectiveTransform & getAFfineTransform What is the difference between findHomography and getPerspectiveTransform. My understanding f

Getting the 5 points used by RANSAC in findHomography (OpenCV for Android)

In OpenCV for Android, the function org.opencv.Calib3d.findHomography(..) returns the homogeneous transformation matrix. For example, this only returns the homography: Mat homography = Calib3d.findHom

Using Distortion Coefficients with findHomography in OpenCV

I am currently lost in the OpenCV documentation and am looking for some guidance on the possible ordering of functions, or perhaps a function within OpenCV that I haven’t came acrossed yet… I am tra

How exactly do I use OpenCV and homographies to undo perspective warp?

I need to use Java and OpenCV to do the process shown on http://en.wikipedia.org/wiki/Perspective_control I know exactly where the 4 points of my trapezoid are, and I just need them to square up. I’ve

OpenCV CV findHomography assertion error – counter => 4

I’m currently finishing my evaluation-tool for interest point detectors. In the last steps I found a confusing error. Mat findHomography(InputArray srcPoints, InputArray dstPoints, int method=0, doubl

Answers

There are several sanity tests you can perform on the output. On top of my head:

  1. Compute the determinant of the homography, and see if it’s too close to zero for comfort.
  2. Even better, compute its SVD, and verify that the ratio of the first-to-last singular value is sane (not too high). Either result will tell you whether the matrix is close to singular.
  3. Compute the images of the image corners and of its center (i.e. the points you get when you apply the homography to those corners and center), and verify that they make sense, i.e. are they inside the image canvas (if you expect them to be)? Are they well separated from each other?
  4. Plot in matlab/octave the output (data) points you fitted the homography to, along with their computed values from the input ones, using the homography, and verify that they are close (i.e. the error is low).

A common mistake that leads to garbage results is incorrect ordering of the lists of input and output points, that leads the fitting routine to work using wrong correspondences. Check that your indices are correct.

But this depends on the point-correspondences you use to compute the homography… Just think that you are trying to find a transformation that maps lines to lines (from one plane to another), so not any possible configuration of point-correspondences will give you an homography that creates nice images. It is even possible that the homography maps some of the points to the infinity.

Understanding the degenerate homography cases is the key. You cannot get a good homography if your points are collinear or close to collinear, for example. Also, huge gray squares may indicate extreme scaling. Both cases may arise from the fact that there are very few inliers in your final homography calculation or the mapping is wrong.

To ensure that this never happens 1. make sure that points are well spread in both images 2. make sure that there are at least 10-30 correspondences (4 is enough if noise is small) 3. make sure that points are correctly matched and the transformation is a homography.

To find bad homographies apply found H to your original points and see the separation from your expected points that is |x2-H*x1|