Ask Your Question
2

Is triangulatePoints outputing rubish ?

asked 2012-10-18 07:25:21 -0600

Guido gravatar image

updated 2012-10-18 07:26:27 -0600

Hi opencv-answers,

I'm trying to use the triangulatePoints functions. However I'm pretty sure it is outputing something wrong. I use some keypoints and triangulate with a method of my own and the opencv function.

Keypoints image 1 / keypoints image 2 / Triangulation own method / Triangulation opencv
351 38 / 365 38 / 7.59634 -20.9415 100.894 / 175.801 225.384 0.897723
347 39 / 362 39 / 6.47411 -18.8165 91.1208 / 210.412 1339.99 5.8723
494 41 / 509 42 / 20.8173 -18.7071 91.7764 / 72.3976 95.5555 0.373354
346 44 / 361 44 / 6.3747 -18.3255 91.0807 / 1920.27 11915.5 52.2264
315 45 / 329 45 / 3.73327 -20.1286 100.571 / 477.627 488.255 2.05914
348 47 / 363 47 / 6.56749 -18.0348 91.0758 / 34.7008 204.819 0.905707
439 47 / 454 47 / 15.5334 -18.2436 92.1344 / 124.85 147.942 0.645297
295 55 / 309 55 / 1.59797 -19.0309 100.404 / 240.789 1329.81 5.88098
482 55 / 496 55 / 22.0522 -19.5136 102.958 / 82.6816 117.328 0.448776
420 59 / 435 59 / 13.6233 -17.0046 91.7702 / 245.919 1327.96 5.88577

Opencv give me a reprojection error of 186467; while my own method gives me 0.13.

For some reason I still want to use the opencv function. Is it bugged, or is there a special way to handle it ? Here is how I call it :

Matx34d P1;
Matx34d P2;
vector<point2f> pts1;
vector<point2f> pts2;
Mat hpts(4, pts1.size(), CV_32F);
Mat pts(3, pts1.size(), CV_32F);

triangulatePoints (P1, P2, Mat(pts1).reshape(1, 2), Mat(pts2).reshape(1, 2), hpts);

I'm using opencv-trunk.

Best regards,

Guido

edit retag flag offensive close merge delete

Comments

I think changing the input and output matrices to CV_64 should resolve the issue and make the output more sensible.

s52gupta gravatar images52gupta ( 2012-10-18 20:20:04 -0600 )edit

I do agree that this could be due to an overflow. However; changing point2f to point2d and CV_32F to CV_64F gives a lot of points at infinity and a reprojection error of NaN.

Guido gravatar imageGuido ( 2012-10-19 05:38:29 -0600 )edit

Has any one found the reason and/or a solution with opencv methods? I think i have a similar problem.

Christian K gravatar imageChristian K ( 2015-04-03 01:11:59 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-10-20 22:59:55 -0600

mgb gravatar image

I've used triangulatepoints sucessfuly, although I got better results with an iterative solution based on the code in Hartley and Zisserman

The different format used by the functions is a little annoying

Call cv::undistortPoints() passing in the screen points as cv::Mat(1,4,CV_64FC2) channel [0]=x, [1]=y, then pass the result to cv::correctMatches()

You then need to convert the result to a cv::Mat(2,n,CV_64FC1) for each 'n' points in left and simalrly in right. Remember you need to generate the projection matrix for each camera with cv::stereoRectify()

The result is 4D value in each column - x,y,z,w so you need to divide x,y,z by w

edit flag offensive delete link more

Comments

Thank you for the extensive answer. So you are saying that triangulatePoints will work at the condition that de points have been undistorded, which I do, and modified by correctMatches. I will take a look at the HZ methode.

Guido gravatar imageGuido ( 2012-10-22 10:40:01 -0600 )edit

Thank you mgb, this is really nice code who works quite well.

Guido gravatar imageGuido ( 2012-11-05 19:48:14 -0600 )edit

Question Tools

Stats

Asked: 2012-10-18 07:25:21 -0600

Seen: 7,910 times

Last updated: Oct 20 '12