Ask Your Question
0

FindHomography

asked 2015-02-01 22:47:59 -0500

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

2 answers

Sort by ยป oldest newest most voted
3

answered 2015-02-02 03:48:43 -0500

Michael Burdinov gravatar image

updated 2015-02-02 09:14:16 -0500

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.

edit flag offensive delete link more

Comments

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.

grsabourin gravatar imagegrsabourin ( 2015-02-02 07:21:14 -0500 )edit
2

answered 2015-02-02 03:51:12 -0500

Eduardo gravatar image

updated 2015-02-02 03:52:41 -0500

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.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2015-02-01 22:47:59 -0500

Seen: 1,447 times

Last updated: Feb 02 '15