Search code examples
matlabmatlab-cvstcoordinate-transformationstereo-3d

Output after Triangulation (MATLAB) isn't accurate


I am using MATLAB- CVST to perform Stereo Camera Calibration. From 28 images (6 X 7 corners), stereoParams are obtained (stereoParams.MeanReprojectionError = 0.3168).

Next, I took took a checkerboard stereo pair (CB_I1 & CB_I2).

To CB_I1 I applied the following functions:

  1. undistortImage
  2. detectCheckerboardPoints
  3. generateCheckerboardPoints
  4. extrinsics: This gives me Translation vector (T) and Rotation Matrix (R)

Next, To both CB_I1 & CB_I2, I apply the following functions:

  1. undistortImage
  2. detectCheckerboardPoints
  3. triangulate: this gives me worldPoints
  4. Inverse Translation and Rotation Transform

This is my code:

CB_I1_undist = undistortImage(CB_I1, stereoParams.CameraParameters1);
CB_I2_undist = undistortImage(CB_I2, stereoParams.CameraParameters2);

[imagePoints1, ~] = detectCheckerboardPoints(CB_I1_undist);
[imagePoints, ~] = detectCheckerboardPoints(CB_I2_undist);

worldPoints = triangulate(imagePoints1,imagePoints,stereoParams);

Translated_pnts = zeros(size(worldPoints));
Translated_pnts(:,1) = worldPoints(:,1) - T(1);
Translated_pnts(:,2) = worldPoints(:,2) - T(2);
Translated_pnts(:,3) = worldPoints(:,3) - T(3);
Rotated_pnts = Translated_pnts * (R');

Transformed_points = Rotated_pnts;

Ultimately, Transformed_points looks like this:

enter image description here

and so on....for 42 points.

How do I interpret this? I expect Transformed_points to be:

enter image description here

since each square size is 40mm.

  • Primarily, is this an error?
  • What is the cause? Is it because of the high reprojection error? (if so, how can it be minimised?)
  • How can I reduce this as much as possible?
  • I want this as close as possible to the ideal value. What are the different ways by which I can improve my algorithm's accuracy?

Let me know if you need any other information.


Solution

  • You say you have a mean re-projection error of 0.3~.

    If I calculate the distance between your first and second point:

    sqrt((-0.2006+0.1993)^2+(-1.2843-39.1922)^2+(3.0466-2.0656)^2)
    ans >>
          40.4884
    

    Well thats what you expect right? Its not 100% accurate of course.

    Also,look again at your points. They are exactly where you expect them to be. Instead of 120 you have 120.06. Instead of 160, you have 159.94.

    you are missing the points by around 0.3 millimeters. 0.3 MILIMETERS. Take a ruler and try to measure 0.3 millimeters!!

    • Thats 4 time a human hair!
    • Its more or less the minimum distance the human eye can distinguish!
    • 3 times the with of paper!
    • 0.6 times the size OF A BACTERIA! (amoeba Proteus)

    WOW, I think thats a quite good error to have, dont you?

    Anyway, you can decrease that error using more calibration images, but yeah, I'd say you are doing a good job already.

    A good way of measuring the error so it has more meaning is to calculate the pixel error, not the real physical error. If you divide the error by the length of a pixel, you can know how many pixels of error you have. You will see that most likely in your case you are having sub-pixel accuracy (pixel error < 1). This is very good because it means that your error is smaller than what you can measure, so, in some sense (not really, but yeah) you are breaking the Shanon principle! Good job


    Source of random data: http://www.wolframalpha.com/input/?i=300+micrometres