python+opencv+matlab实现双目标定和测距

  • Post author:
  • Post category:python


0 准备工作

1 双目相机标定


1.1  获取标定图片并分割左右图片

python代码

import cv2

#分割双目图片
def divide_img(img): #i=0横向分割 默认i=1纵向分割
    h = img.shape[0]
    w = img.shape[1]
    L_img = img[0:h, 0:int(w/2), :]
    R_img = img[0:h, int(w/2):w, :]
    return L_img, R_img

#读取摄像头
cap=cv2.VideoCapture(0)
i=1
while True:
    ret, frame=cap.read()
    #frame = cv2.flip(frame,1) 
    cv2.imshow('frame',frame)
    if cv2.waitKey(1)==ord('s'):
        #cv.resize(frame,(640,480))
        cv2.imwrite('./cap_data/img%d.jpg'%i,frame)
        print('had written img%d.jpg'%i, frame.shape)
        L_img, R_img = divide_img(frame)
        cv2.imwrite('./cap_data/L_img/L_img%d.jpg'%i,L_img)
        cv2.imwrite('./cap_data/R_img/R_img%d.jpg'%i,R_img)
        #print('had written img%d.jpg'%i, frame.shape)
        i+=1   
    elif cv2.waitKey(5)==ord('q'):
        break
img1.jpg

L_img1.jpg
R_img1.jpg

1.2 用Matlab进行标定



版权声明:本文为njupt_18ptgd_lhj原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。