# Matlab calibration to opencv

**URL:** https://forum.opencv.org/t/matlab-calibration-to-opencv/15974
**Category:** Python
**Tags:** calib3d, stereo-calibration, build
**Created:** [December 26, 2023, 4:51pm UTC](https://forum.opencv.org/t/matlab-calibration-to-opencv/15974 "2023-12-26T16:51:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Mostafa\_Mohamed](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mostafa_mohamed/32/7218_2.png) [@Mostafa\_Mohamed](https://forum.opencv.org/u/Mostafa_Mohamed)
#### Post date: [December 26, 2023, 4:51pm UTC](https://forum.opencv.org/t/matlab-calibration-to-opencv/15974/1 "2023-12-26T16:51:40Z")

</div>

hello i extracted the following stereo camera parameters from matlab , i dont know to to make it in opencv format

## Camera 1 Intrinsics

Focal length (pixels): [1062.8663 +/- 1.7473 1062.1262 +/- 1.7367]  
Principal point (pixels):[958.0507 +/- 0.3169 545.8194 +/- 0.3959]  
Radial distortion: [0.0213 +/- 0.0003 -0.0232 +/- 0.0003]

## Camera 2 Intrinsics

Focal length (pixels): [1057.7849 +/- 1.7440 1056.6368 +/- 1.7317]  
Principal point (pixels):[968.4359 +/- 0.3319 545.3497 +/- 0.3909]  
Radial distortion: [0.0222 +/- 0.0003 -0.0245 +/- 0.0003]

## Position And Orientation of Camera 2 Relative to Camera 1

Rotation of camera 2: [-0.0019 +/- 0.0001 0.0093 +/- 0.0001 0.0012 +/- 0.0000]  
Translation of camera 2 (millimeters):[-59.6460 +/- 0.0055 0.1108 +/- 0.0041 0.4209 +/- 0.0115]

**i used it as it is with the following but the rectification became really bad**

> # Compute rectification maps

R1, R2, P1, P2, Q, \_, \_ = cv2.stereoRectify(  
camera\_matrix1, dist\_coeff1,  
camera\_matrix2, dist\_coeff2,  
(left\_img.shape[1], left\_img.shape[0]),  
R, T,  
flags=cv2.CALIB\_ZERO\_DISPARITY, alpha=-1  
)

# Compute rectification maps

map1\_left, map2\_left = cv2.initUndistortRectifyMap(  
camera\_matrix1, dist\_coeff1, R1, P1,  
(left\_img.shape[1], left\_img.shape[0]), cv2.CV\_16SC2  
)

map1\_right, map2\_right = cv2.initUndistortRectifyMap(  
camera\_matrix2, dist\_coeff2, R2, P2,  
(right\_img.shape[1], right\_img.shape[0]), cv2.CV\_16SC2  
)

# Remap the images using the rectification maps

left\_img\_rectified = cv2.remap(left\_img, map1\_left, map2\_left, cv2.INTER\_LINEAR)  
right\_img\_rectified = cv2.remap(right\_img, map1\_right, map2\_right, cv2.INTER\_LINEAR)
