5

I was trying to use the new RHO homography algorithm in conjunction with perspectiveTransform, but it seems that the homography matrix calculated by RHO has a wrong size and consequently it is not compatible with that method.

See code below:

H = findHomography(obj_points, scn_points, RHO, 1.0);
perspectiveTransform(obj_corners, scene_corners, H);

Following assertion fails:

error: (-215) scn + 1 == m.cols in function perspectiveTransform

Any clue? It works perfectly with RANSAC.

Pablo
  • 1,041
  • 8
  • 23
  • I do not know about RHO method. But it may be threshold problem.. try to change 1.0 to the most flexible possible value ( I mean a threshold that accept the dumbest homography) – Humam Helfawi Jan 18 '16 at 12:34
  • Well, in their examples they use 1.0 as threshold: http://www.cvrobot.net/wp-content/uploads/2015/06/OpenCV3_CVPR_2015_Modules.pptx. I've also tried with other threshold values without luck. – Pablo Jan 18 '16 at 12:38
  • Unfortnatnyl I do not have OpenCV 3.1 to try it right now. However, your problem seems strange while you can put RANSAC and everything works fine! The only thing that came in my mind that this algorithm may fail to find homography in some extreme cases (which is not logical since any 4 non collinear points can produce a homography) but I can not think with any other possibility.. Good Luck! – Humam Helfawi Jan 18 '16 at 12:45
  • BTW how many pairs you have? – Humam Helfawi Jan 18 '16 at 12:46
  • About 50 good matches. I also check that good_matches >= 4 before computing homography. – Pablo Jan 18 '16 at 12:58
  • I do not think that I am able to help. But in order to get better help from the guys, I recommended to print out the H and post it here. – Humam Helfawi Jan 18 '16 at 13:19

1 Answers1

2

I've found the solution:

With RHO, I have to check the homography matrix to ensure it is not empty. Giving 4 or more points to findHomography is not enough to get an homography matrix with this method.

Although giving to it about 50 matches to compute, it only retrieves a non empty matrix 40-50% of the times.

Pablo
  • 1,041
  • 8
  • 23
  • 2
    (One of) the authors of RHO speaking here. I would love to see your testcase in, say, a Pastebin! Are many of your points on the same column or row? Also, do you perform any sort of normalization on the input points beforehand? I believe that our algorithm actually does _worse_ when points are pre-treated this way. Why is not yet clear to me; We optimized for pure speed (writing our own numerical solvers based on cheap but less numerically stable algorithms) and recognize we may lose accuracy. – Iwillnotexist Idonotexist Jan 20 '16 at 02:39
  • 1
    @IwillnotexistIdonotexist of course. here you have the code of my detection method: http://pastebin.com/mK2jZ83Q – Pablo Jan 21 '16 at 08:37