opencv获取matlab工具箱标注的双目参数

1.注意:使用matlab矫正时,camera1一定对应左,camera2一定对应右!!!!

stereo_camera_config

import cv2
import numpy as np

#stereoParams.CameraParameters1.IntrinsicMatrix
#ans'
right_camera_matrix = np.array([[372.9499 ,       0,  339.9497],
                               [0  ,371.2997,  289.0286],
                               [0     ,    0   , 1.0000]])
                               
         
#stereoParams.CameraParameters1   
#顺序:RadialDistortion[0],RadialDistortion[1],TangentialDistortion[0],TangentialDistortion[1],RadialDistortion[2]
right_distortion = np.array([[-0.0303 ,0.0886,0,0 -0.0646]])


#使用时,需要注意参数的排放顺序,即K1,K2,P1,P2,K3。切记不可弄错,否则后续的立体匹配会出现很大的偏差。
#stereoParams.CameraParameters2.IntrinsicMatrix
#ans'
left_camera_matrix = np.array([[368.3098    ,     0  ,357.8760],
                                [0  ,367.6755  ,248.2351],
                                [0     ,    0    ,1.0000]])   
#stereoParams.CameraParameters2                        
                                             
left_distortion = np.array([[0.0163, -0.0502,0,0 ,0.0247 ]])
#stereoParams  
R = np.matrix([
    [ 0.997114422566844,-0.013467397037999,0.074709152894473],
    [  0.012913244142177,0.999885447384289,0.007895583249125],
    [ -0.074806927720054,-0.006908062401299,0.997174108287488],
])


# print(R)

T = np.array([3.151885008307438e+02,0.262068133059456,8.907585308658991]) # 平移关系向量

size = (640, 480) # 图像尺寸

# 进行立体更正
R1, R2, P1, P2, Q, validPixROI1, validPixROI2 = cv2.stereoRectify(left_camera_matrix, left_distortion,
                                                                  right_camera_matrix, right_distortion, size, R,
                                                                  T)
# 计算更正map
left_map1, left_map2 = cv2.initUndistortRectifyMap(left_camera_matrix, left_distortion, R1, P1, size, cv2.CV_16SC2)
right_map1, right_map2 = cv2.initUndistortRectifyMap(right_camera_matrix, right_distortion, R2, P2, size, cv2.CV_16SC2)

# print(Q)

根据标定好的参数,进行矫正

import cv2
# 根据标定数据对图片进行重构消除图片的畸变
img1_rectified = cv2.remap(frame1, camera_configs.left_map1, camera_configs.left_map2, cv2.INTER_LINEAR)
img2_rectified = cv2.remap(frame2, camera_configs.right_map1, camera_configs.right_map2, cv2.INTER_LINEAR)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值