Possible breaking change in cvStereoCalibrate (Bug #1905)


Added by Aggelos Biboudis almost 13 years ago. Updated almost 13 years ago.


Status:Cancelled Start date:2012-05-08
Priority:Normal Due date:
Assignee:Ilya Lysenkov % Done:

0%

Category:calibration, 3d
Target version:2.4.1
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

I have discovered an inconsistency in the expected results between building with 2.3.1 and by just updating to 2.4.0.
The final vector of CvPoint3D32f points I am constructing, after cvStereoCalibrate in 2.3.4 was always filled with correct points like { 51, 34, 549 }, {83, 49, 599}, etc but when I build it with 2.4.0 all the z-coords are negative and appear scaled { 51, 34, -400}, {83, 49, -410}.

I will update the issue with more information, later.


calib-utility.zip (3.5 MB) Aggelos Biboudis, 2012-05-10 12:54 pm


History

Updated by Ilya Lysenkov almost 13 years ago

Thank you for the report, it is the important issue. Please provide a minimum sample (code and data) that returns incorrect results. It will allow us to reproduce the problem and fix it soon.

Updated by Ilya Lysenkov almost 13 years ago

  • Category set to calibration, 3d

Updated by Aggelos Biboudis almost 13 years ago

As I can't post excerpt of my code for various reasons, I did reproduce it with the following code as an example from the well-known blog of Martin Perishttp://blog.martinperis.com/2011/01/opencv-stereo-camera-calibration.html. In my application, I rotate the images, I extract the points that interest me, I undistort them and then I find the stereoscopic position manually. This somehow resembles what I did in my code.

So to reproduce it:

  1. Open the solution with visual studio 10.
  2. Setup up the linker to use the 2.3.1 dlls.
  3. Run it (I have included some of our training images).
  4. Go to main function, comment StereoCalib function call, in line 543 and uncomment RemapPoint call in 545.
  5. Hit CTRL+F5 and see the position of a certain point from the first pair of images. (it should be X: -53.6805 Y: 63.6227 Z: 346.78 and the X is ok to be negative)
  6. Clear all the xml files that the code saved in the working directory.
  7. Reverse the function calls commenting from step 4.
  8. Repeat steps 2-5 with the 2.4.0 dlls. (the result is now X: 49.6927 Y: -58.8963 Z: -321.019)
  • File calib-utility.zip added

Updated by Ilya Lysenkov almost 13 years ago

  • Assignee set to Ilya Lysenkov

Updated by Ilya Lysenkov almost 13 years ago

Thank you for the code and detailed instructions. I was able to reproduce the problem and get negative Z with 2.4.0.

As far as I understand, you pass *M.tif as images from the first camera (left) and *S.tif as images from the second camera (right). But *M.tif images correspond to the right camera and *S.tif correspond to the left camera. So you should swap these images to get correct results.

Also notice that you don't need to rotate images because OpenCV can handle both left-right and up-down positions of cameras. So you can just rotate images back and pass them to OpenCV (in this case you don't need to swap *M.tif and *S.tif images).

I tried both variants (either swapping the images or rotating them back) and I got correct (positive) Z values in both cases with 2.4.0.

Does it solve your problem?

P.S. Note that you can use OpenCV functions cv::triangulatePoints and cv::reprojectImageTo3D to reconstruct 3D positions of points instead of manual processing of the Q matrix. See OpenCV docs.

Updated by Aggelos Biboudis almost 13 years ago

I understand my inconsistency between left-right -> up-down. It should be down first and up second. And that is what I am going to fix my app for 2.4.0. But why in 2.3.1 we get correct coordinates with the opposite sequence?

Which OpenCV function can we use for up-down stereo calibration? And will we get the same accuracy as with the left-right?

Thank you very much for you immediate response (and for the triangulatePoints , reprojectImageTo3D tip).

Updated by Ilya Lysenkov almost 13 years ago

You can use the same cv::stereoCalibrate function for up-down stereo calibration. The up camera should be first and the down camera should be second. I think the accuracy will be the same because it is essentially the same code as with the left-right positions.

2.3.1 has a bug regarding to computation of the Q matrix (see #898 issue). It was fixed in 2.4.0 so you should use this version of OpenCV.

  • Status changed from Open to Cancelled

Also available in: Atom PDF