# FindHomography

I have some difficulties with very simple use of FindHomography. This is my simple code.

std::vector<cv::Point2f> P1(3);
P1[0].x = 10;  P1[0].y = 10;
P1[1].x = 20;  P1[1].y = 20;
P1[2].x = 30;  P1[2].y = 30;

std::vector<cv::Point2f> P2(3);
P2[0].x = 210; P2[0].y = 210;
P2[1].x = 220; P2[1].y = 220;
P2[2].x = 230; P2[2].y = 230;

cv::Mat T;
T = cv::findHomography( mat_p1, mat_p2, 0 );

The result matrix is

[-1.#IND, -1.#IND, -1.#IND; 1.#INF, -1.#INF, -1.#IND; -1.#IND, -1.#IND, -1.#IND]

edit retag close merge delete

Sort by ยป oldest newest most voted

FindHomography need to calculate perspective transform. Perspective transform has 8 parameters. This means that it requires at least 8 equations to get single solution. In other words you need to provide at least 4 pairs of points to FindHomography.

Edit: Just having 4 pairs of points is not enough. System of 8 equations with 8 unknown variables can't be solved if there linear dependence between equations. The points you used are on the same line. This create linear dependence and makes the system unsolvable. You should not use co-linear segments.

more

you are right it needs more 4 or more pairs of points and OpenCV send assert if it os <4. I did a wrong cut/paste operation for creating my message. The right code is this one

std::vector<cv::Point2f> P1(4);
P1[0].x = 10;  P1[0].y = 10;
P1[1].x = 20;  P1[1].y = 20;
P1[2].x = 30;  P1[2].y = 30;
P1[3].x = 40;  P1[3].y = 40;

std::vector<cv::Point2f> P2(4);
P2[0].x = 210; P2[0].y = 210;
P2[1].x = 220; P2[1].y = 220;
P2[2].x = 230; P2[2].y = 230;
P2[3].x = 240; P2[3].y = 240;

cv::Mat T;
T = cv::findHomography( P1, P2, 0 );

I have also tried with 10 pairs of points with the same result.

( 2015-02-02 07:21:14 -0500 )edit

Edit: Same answer than Michael Burdinov.

Hi, I think the problem is that you use 3 points but the minimal number of points to estimate an homography is 4, so the system is undertermined.

more

Official site

GitHub

Wiki

Documentation