tufekoi
tufekoi

Reputation: 991

what does the result of triangulatePoints() from openCV should looks like?

I'm trying to triangulate some points from a stereo camera system.

First, I used the sample "stereo_calib" (cpp) to get the extrinsic parameters in a yml file :

Is there a way to check if the values are correct ?

Then I use the method:

cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2, CvMat* projPoints1, CvMat* projPoints2, CvMat* points4D) 

I used P1 for projMatr1 and P2 for projMatr2.

The point I want to triangulate is at coordinate x=919,y=686 on left image and x=586,y=694 on the right one. I tried this but I'm not sure if it's the good way:

int co1[] = {919,686};
Mat point1(2, 1, CV_32FC1, co1);
int co2[] = {586,694};
Mat point2(2, 1, CV_32FC1, co2);
Mat points4D;

I used point1 for projPoints1 and point2 for projPoints2. I wrote points4D in a yml file at the end. This is the result I got:

%YAML:1.0
Points4D: !!opencv-matrix
    rows: 4
    cols: 1
    dt: f
    data: [ 2.34857202e-001, 1.03716120e-001, -9.66480732e-001,
            1.43435571e-007 ]

What does it mean ? The three first values are x, y and z of the reconstruct point ? The values seems strange to me, but I'm really knew with openCV do I don't know much about it.

I found this related question: How to correctly use cv::triangulatePoints(). But it didn't really help me...

Thanks for the help !

EDIT

the calibration gives me this:

P1: !!opencv-matrix
    rows: 3
    cols: 4
    dt: d
    data: [ 1.5334888857352591e+003, 0., 1.1192188110351562e+003, 0., 0.,
            1.5334888857352591e+003, 9.1114062500000000e+002, 0., 0., 0., 1.,
            0. ]
P2: !!opencv-matrix
    rows: 3
    cols: 4
    dt: d
    data: [ 1.5334888857352591e+003, 0., 1.1192188110351562e+003,
            4.3953258083993223e+003, 0., 1.5334888857352591e+003,
            9.1114062500000000e+002, 0., 0., 0., 1., 0. ]

I used the chessboard in the doc print on a A4 format paper.

Upvotes: 2

Views: 5475

Answers (1)

AndroC
AndroC

Reputation: 4884

You should first calibrate your cameras separately and obtain intrinsic matrix for both of them.

Then you can run stereo calibration with special flags indicating that you are searching only for extrinsic properties (cameras' relation to each other).

Projection matrices (like P1 and P2) are essentially a multiplication of camera's intrinsic matrix C and camera's extrinsic matrix [R|t].

One way to check your results is to use the R and T values you got from stereo calibration and create a Fundamental Matrix that will describe the relation of images shot by one camera with images shot by the other camers.

Using Fundamental Matrix, for each point on image shot by camera A, you can draw a line on the image shot by camera B. If you cann see with your eyes the actual corresponding point lays directly on that line, that is good.

If you repeat that for multiple points and always get good results, you can be failry certain that your extrinsic properties are fine and that your projection matrices are fine.

When you get the 3d points as a result of triangulatePoints function, they are in homogeneous coordinates (x, y, z, w). The Euclidian coordinates of that point are (x/w, y/w, z/w).

Side note:

Printing a chessboard on a paper is rarely a good idea. The paper is usually never perfectly plain / straight. One way is to print it on a sticky paper and glue it without underlying bubbles on a hard plain surface. You can also try and simply display the chessboard pattern on a computer display and report with the results :)

Upvotes: 3

Related Questions