Stereo Calibration - Export from Matlab to ROS
I am trying to calibrate a pair of ueye cameras, model CP USB 3.0.
if I use the camera calibrator node the quality of calibration is really bad. I followed this guide step by step
http://wiki.ros.org/camera_calibration/Tutorials/StereoCalibration
After calibration I clicked commit and I ended up with two files in my driver ueye node. I can then start the driver and I see in topic camera_info that the calibration file has been loaded.
Then I run stereoimageproc node to rectify the images, but I get a very bad result. Topics imagerectcolor and image_color are almost the same, meaning the calibration is almost not doing much and the images are not well rectified.
I then tried to perform calibration again using the Matlab computer vision toolbox, stereo calibration app.
https://nl.mathworks.com/help/vision/ug/stereo-camera-calibrator-app.html
With this one I get a much better calibration and the images are well rectified, but now I don't know how to export the results from Matlab to the .ini calibration files used by the ueye driver.
I am attaching the files with the results for both ROS and Matlab. Could you please help me translate the results from Matlab into ROS?
I understand the camera matrix, but I don't know how to correctly match the results from Matlab into the Distortion, Rectification and Projection Matrices of the .ini calibration files.
MATLAB RESULTS
Camera 1 Intrinsics
-------------------
Focal length (pixels): [ 1461.7220 +/- 2.6474 1474.2012 +/- 2.6417 ]
Principal point (pixels):[ 967.4086 +/- 1.4924 605.6235 +/- 1.2613 ]
Radial distortion: [ -0.1466 +/- 0.0027 0.1859 +/- 0.0218 -0.1559 +/- 0.0512 ]
Tangential distortion: [ 0.0013 +/- 0.0002 -0.0001 +/- 0.0002 ]
Camera 1 Extrinsics
-------------------
Rotation vectors:
[ -0.2224 +/- 0.0042 0.0308 +/- 0.0032 0.0819 +/- 0.0004 ]
[ -0.3702 +/- 0.0017 0.1900 +/- 0.0017 -0.1542 +/- 0.0004 ]
[ -0.2243 +/- 0.0014 -0.0319 +/- 0.0015 0.0321 +/- 0.0003 ]
[ -0.1585 +/- 0.0017 -0.0929 +/- 0.0017 0.0388 +/- 0.0002 ]
[ -0.1432 +/- 0.0028 -0.1294 +/- 0.0025 0.0287 +/- 0.0002 ]
[ -0.1654 +/- 0.0023 -0.1418 +/- 0.0022 0.0294 +/- 0.0003 ]
[ -0.1599 +/- 0.0015 -0.1060 +/- 0.0020 0.0091 +/- 0.0003 ]
[ -0.1778 +/- 0.0014 -0.0985 +/- 0.0015 -0.0059 +/- 0.0002 ]
[ -0.0896 +/- 0.0020 -0.0548 +/- 0.0020 0.0570 +/- 0.0002 ]
[ 0.0955 +/- 0.0027 -0.3056 +/- 0.0021 0.1882 +/- 0.0004 ]
[ -0.0263 +/- 0.0013 -0.0513 +/- 0.0013 -0.0077 +/- 0.0001 ]
[ -0.1241 +/- 0.0012 -0.0498 +/- 0.0013 0.0662 +/- 0.0001 ]
[ -0.1763 +/- 0.0009 -0.1665 +/- 0.0011 -0.0308 +/- 0.0001 ]
[ -0.1448 +/- 0.0010 0.0007 +/- 0.0012 0.0004 +/- 0.0001 ]
[ -0.1954 +/- 0.0009 0.0887 +/- 0.0011 0.0147 +/- 0.0002 ]
[ -0.1018 +/- 0.0010 -0.0225 +/- 0.0012 0.0400 +/- 0.0002 ]
[ -0.2833 +/- 0.0010 -0.0481 +/- 0.0012 0.0655 +/- 0.0003 ]
[ -0.2673 +/- 0.0011 -0.0353 +/- 0.0013 0.0613 +/- 0.0003 ]
[ -0.2400 +/- 0.0010 -0.1310 +/- 0.0012 0.0139 +/- 0.0003 ]
[ -0.1872 +/- 0.0010 -0.4869 +/- 0.0011 0.0850 +/- 0.0003 ]
[ -0.1372 +/- 0.0010 0.4043 +/- 0.0011 0.0079 +/- 0.0003 ]
[ -0.2668 +/- 0.0010 0.0763 +/- 0.0013 0.0673 +/- 0.0003 ]
[ -0.3185 +/- 0.0010 0.1071 +/- 0.0013 0.1016 +/- 0.0003 ]
[ -0.1924 +/- 0.0011 -0.0543 +/- 0.0016 0.0347 +/- 0.0003 ]
[ -0.2141 +/- 0.0031 -0.0904 +/- 0.0027 0.0102 +/- 0.0004 ]
[ -0.2962 +/- 0.0013 0.1979 +/- 0.0015 0.1666 +/- 0.0003 ]
[ -0.2329 +/- 0.0014 0.2507 +/- 0.0016 0.1072 +/- 0.0003 ]
[ -0.4455 +/- 0.0010 0.0657 +/- 0.0013 0.0478 +/- 0.0003 ]
Translation vectors (mm):
[ -27.3688 +/- 4.6863 686.6278 +/- 3.9494 4556.9159 +/- 8.4226 ]
[ 1345.4758 +/- 4.7236 260.3475 +/- 3.9415 4512.4819 +/- 8.1310 ]
[ 845.9191 +/- 4.5234 -43.4737 +/- 3.7768 4388.7133 +/- 7.9743 ]
[ 224.5362 +/- 4.3927 -26.8464 +/- 3.6798 4299.5410 +/- 7.8017 ]
[ -553.4422 +/- 4.3697 3.4960 +/- 3.6578 4258.9825 +/- 7.8142 ]
[-1336.4990 +/- 4.5027 -28.5861 +/- 3.7760 4337.2182 +/- 8.1786 ]
[-2101.7058 +/- 4.6412 78.0932 +/- 3.8339 4311.2618 +/- 8.6402 ]
[ 164.0388 +/- 4.4180 -534.1853 +/- 3.6690 4307.4159 +/- 7.8280 ]
[ -193.0901 +/- 4.5434 -648.9557 +/- 3.7734 4428.3718 +/- 8.0820 ]
[ -904.1278 +/- 4.3223 -750.4679 +/- 3.5465 4107.8499 +/- 7.9046 ]
[ -104.8165 +/- 2.5506 -90.9017 +/- 2.1385 2493.6455 +/- 4.5257 ]
[ -28.8709 +/- 2.4540 11.6334 +/- 2.0544 2400.8976 +/- 4.3351 ]
[ -192.0852 +/- 2.1984 -70.5768 +/- 1.8371 2147.5935 +/- 3.9008 ]
[ -172.2495 +/- 2.3014 -242.8060 +/- 1.9165 2250.6563 +/- 4.0849 ]
[ -149.0356 +/- 2.4024 -475.1546 +/- 1.9800 2333.5014 +/- 4.2001 ]
[ -98.0068 +/- 2.6034 -960.4608 +/- 2.0880 2457.2724 +/- 4.6348 ]
[ -139.2022 +/- 3.2557 -856.1206 +/- 2.6557 3129.9775 +/- 5.7270 ]
[ -285.7654 +/- 3.7148 -815.0099 +/- 3.0523 3591.4929 +/- 6.5556 ]
[ -595.8079 +/- 2.9485 -837.6156 +/- 2.4146 2818.5653 +/- 5.3382 ]
[ -457.4853 +/- 2.8540 -742.9442 +/- 2.3546 2732.3957 +/- 5.2289 ]
[ -298.1419 +/- 3.2046 -617.5335 +/- 2.6639 3104.9099 +/- 5.3670 ]
[-1311.7135 +/- 4.3333 -653.2931 +/- 3.5868 4139.9300 +/- 7.7728 ]
[-1716.5151 +/- 4.5770 -709.5365 +/- 3.7553 4300.2073 +/- 8.2648 ]
[-1958.2422 +/- 4.4817 -751.4705 +/- 3.6561 4157.6330 +/- 8.3278 ]
[-1072.9880 +/- 4.7059 626.9915 +/- 3.9675 4536.5414 +/- 8.4759 ]
[ 365.1864 +/- 4.5842 -359.3245 +/- 3.8226 4477.7480 +/- 7.8333 ]
[ 893.8858 +/- 4.0594 -388.0017 +/- 3.3693 3925.4751 +/- 6.9549 ]
[ 501.4885 +/- 4.0697 -292.3820 +/- 3.3884 3966.3023 +/- 6.9276 ]
Camera 2 Intrinsics
-------------------
Focal length (pixels): [ 1461.8452 +/- 2.6400 1473.6840 +/- 2.6362 ]
Principal point (pixels):[ 955.8111 +/- 1.4967 594.0218 +/- 1.2772 ]
Radial distortion: [ -0.1397 +/- 0.0019 0.1085 +/- 0.0123 0.0314 +/- 0.0224 ]
Tangential distortion: [ 0.0013 +/- 0.0001 0.0016 +/- 0.0002 ]
Position And Orientation of Camera 2 Relative to Camera 1
---------------------------------------------------------
Rotation of camera 2: [ 0.0008 +/- 0.0003 -0.0012 +/- 0.0005 0.0018 +/- 0.0000 ]
Translation of camera 2 (mm): [ -357.7830 +/- 0.0815 -2.9665 +/- 0.0643 -1.2721 +/- 0.4898 ]
ROS CALIBRATION
# oST version 5.0 parameters
[image]
width
1936
height
1216
[narrow_stereo/left]
camera matrix
1457.697262 0.000000 962.523495
0.000000 1472.744867 601.155581
0.000000 0.000000 1.000000
distortion
-0.142828 0.107103 -0.000149 0.000011 0.000000
rectification
0.999238 0.003380 -0.038895
-0.003245 0.999988 0.003548
0.038907 -0.003419 0.999237
projection
1469.022959 0.000000 1034.340347 0.000000
0.000000 1469.022959 590.191238 0.000000
0.000000 0.000000 1.000000 0.000000
# oST version 5.0 parameters
[image]
width
1936
height
1216
[narrow_stereo/right]
camera matrix
1466.613061 0.000000 954.633210
0.000000 1478.548217 576.923859
0.000000 0.000000 1.000000
distortion
-0.135514 0.104181 0.000768 0.000866 0.000000
rectification
0.999351 0.004365 -0.035758
-0.004490 0.999984 -0.003404
0.035743 0.003563 0.999355
projection
1469.022959 0.000000 1034.340347 -526.890893
0.000000 1469.022959 590.191238 0.000000
0.000000 0.000000 1.000000 0.000000
---------------------------------- EDIT 2 Feb 2017 ----------------------------------
I have re-run the calibration in better conditions and have updated the values. I am using the same images for both Matlab and ROS. Why are the results so different?
And can someone please help me translate the values from Matlab into the ROS calibration files? Because I am sure the Matlab calibration gives well rectified images, while the rectcolor images from stereoprocessing node of ROS are always poorly rectified.
I do not understand why the rectification matrices are like that in ROS. Shouldn't the rotation matrix be the identity for the left camera and for the right camera express the rotation with respect to the left? Is there a ROS documentation explaining how exactly the distortion, rectification and projection matrices are computed?
Asked by Steve3nto on 2017-02-01 08:42:36 UTC
Comments
Hi, did you find an answer by now? I'm facing the same problem, but can't translate the matlab stereoParams to the ROS projection matrix and rectification matrix. Anybody who can help?
Asked by mherrmann on 2018-08-29 04:47:03 UTC
I am also trying to get the projection and rectification matrix . I think [https://stackoverflow.com/questions/46651936/convert-between-matlab-stereoparameters-and-opencv-stereorectify-stereo-calibrat] would be useful. I converted first using cv2 and python and changed the parameters.
Asked by pravin1 on 2019-06-15 11:56:06 UTC