# Check if homography is good

Basically I a am using a function

bool niceHomography(const CvMat * H)
{
const double det = cvmGet(H, 0, 0) * cvmGet(H, 1, 1) - cvmGet(H, 1, 0) * cvmGet(H, 0, 1);
if (det < 0)
return false;

const double N1 = sqrt(cvmGet(H, 0, 0) * cvmGet(H, 0, 0) + cvmGet(H, 1, 0) * cvmGet(H, 1, 0));
if (N1 > 4 || N1 < 0.1)
return false;

const double N2 = sqrt(cvmGet(H, 0, 1) * cvmGet(H, 0, 1) + cvmGet(H, 1, 1) * cvmGet(H, 1, 1));
if (N2 > 4 || N2 < 0.1)
return false;

const double N3 = sqrt(cvmGet(H, 2, 0) * cvmGet(H, 2, 0) + cvmGet(H, 2, 1) * cvmGet(H, 2, 1));
if (N3 > 0.002)
return false;

return true;
}


to check whatever the homography is good or not (I have taken it from BRIEF_demo). Can anyone explain why we check the determinant like that, is there any theory behind it?

To understand what I am talking about, that function avoids homography like this:

Thanks

edit retag close merge delete

Sort by ยป oldest newest most voted

I can partially explain that, this explanation was taken from the book "Multiple View Geometry".

Property of an affine (and projective?) transformation:

• If the determinant of the top-left 2x2 matrix is > 0 the transformation is orientation-preserving.
• Else if the determinant is < 0, it is orientation-reversing.
more

Hmm thanks a lot! anyway i think we have a 3x3 Matrix as explained by opencv doc

( 2012-09-25 09:32:17 -0500 )edit

The answer means the top-left 2x2 matrix inside the 3x3 Matrix.

( 2012-09-25 12:14:32 -0500 )edit

and if those two conditions are not satisfied then homography matrix is wrong?

( 2017-11-29 17:55:55 -0500 )edit

In my knowledge, if vertical lines are not vertical then homography matrix is not good. Is this correct?

( 2017-11-29 17:59:33 -0500 )edit

Or you mean if we preserve orientation then homography matrix is good?

( 2017-11-29 18:13:18 -0500 )edit

The homography matrix is not good in itself. It really depends on the use case. If you are trying to match pictures in a mirror, then a "orientation-reversing" homography is needed and other should be discarded. (For example)

( 2019-04-23 08:16:35 -0500 )edit

Official site

GitHub

Wiki

Documentation