triangulatepoints returns very bad results [closed]

asked 2017-02-22 11:34:28 -0600

Correlator gravatar image

updated 2017-02-23 02:17:41 -0600

Hello, I'm new in CV and trying to calculate 3D-Coordinates of a point with a stereo-setup. I don't get useful results from my code and the posts/questions of other users also didn't helped me. I did the following things:

Step 1: Calibrate both cameras individually with a chessboard to get the intrinsic (camera matrix and distortion coefficients) parameters. I used the cv::calibrateCamera() function which returned an reprojection error smaller than 0.2 for both cameras.

Step2: Stereo Calibrate of the Setup with a chessboard to get the rotation and translation matrix. I checked the result. The Error was very small and the T-Vector values are correlated to the physical setup (about 12.5 cm Basline).

Step 3: Getting the projection matrices for both cameras P1 and P2 using the cv::stereoRectify() function.

Now i want to triangulate.

  1. I took a capture with both cameras and remapped the captures using the function cv::initUndistortRectifyMap() and cv::remap().

  2. I detected the centre of the ball. You can find the images and my Calibration results under this link: Dropbox Link

In the left picture it was on pixel: x=343/y=272 and on the right picture it was on x=296/y=272.With these inputs i was trying the get 3D-coordinates of the point with the following code:

int co1[] = {343,272};
Mat point1(2, 1, CV_32FC1, co1);
int co2[] = {296,272};
Mat point2(2, 1, CV_32FC1, co2)
Mat points4D;
triangulatePoints(P1,P2,point1,point2,points4D);

for this input i got the following output from triangulatepoints: [5.21432042e-001, 4.01907146e-001, -7.52714634e-001, -1.1737522e-018]

The result also doesn't change if I change the pixel-coordinates manually. Can you tell me what i am doing wrong? Do i have a logical error about how triangulatePoints works?The actual position of the point is about [0;0;125]cm if you take the left camera as origin.

Ty for your help

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Correlator
close date 2017-02-23 05:41:23.615124

Comments

I think I gave you enough karma to post links. Could you also include your P1 and P2?

Tetragramm gravatar imageTetragramm ( 2017-02-22 17:49:47 -0600 )edit

Ty very much. I have edited my Question. Here are m P1 and P2 matrices. The other matrices are included in the link.

P1: !!opencv-matrix
   rows: 3
   cols: 4
   dt: d
   data: [ 4.7156901179708200e+002, 0., 3.2667253875732422e+002, 0., 0.,
       4.7156901179708200e+002, 2.5179125213623047e+002, 0., 0., 0., 1.,
       0. ]
P2: !!opencv-matrix
   rows: 3
   cols: 4
   dt: d
   data: [ 4.7156901179708200e+002, 0., 3.2667253875732422e+002,
       -5.8735110439944547e+003, 0., 4.7156901179708200e+002,
       2.5179125213623047e+002, 0., 0., 0., 1., 0. ]
Correlator gravatar imageCorrelator ( 2017-02-23 02:22:38 -0600 )edit

Hello, i have solved it. The points had wrong values, should have checked them before asking. Here is how it works for me now:

vector<Point2f> point1;
point1.push_back(cv::Point(343, 272));
Mat point1Mat = Mat(point1);

vector<Point2f> point2;
point2.push_back(cv::Point(296, 272));
Mat point2Mat = Mat(point2);
Correlator gravatar imageCorrelator ( 2017-02-23 05:38:30 -0600 )edit