差异映射双镜头StereoSGBM OpenCV3 Python2.7

时间:2016-09-13 10:14:48

标签: python python-2.7 computer-vision opencv3.1

  1. 我无法校准双镜头相机以获得视差图。我附上了图片和源代码。我已经尝试了千种变量组合,这是我用这台相机完成的最好的。使用像Logitech C270这样的其他相机,我没有遇到这个问题。
  2. 双镜头相机http:// i.stack.imgur.com/qKDz2.jpg 查看http://i.stack.imgur.com/P1cYq.jpg 差异地图结果http://i.stack.imgur.com/l1GoC.png

    import numpy as np
    import cv2
    
    l_camera = cv2.VideoCapture(2)
    r_camera = cv2.VideoCapture(0)
    
    # create windows
    cv2.namedWindow('left_Webcam', cv2.WINDOW_NORMAL)
    cv2.namedWindow('right_Webcam', cv2.WINDOW_NORMAL)
    cv2.namedWindow('disparity', cv2.WINDOW_NORMAL)
    
    blockSize = 40
    
    while(cv2.waitKey(1) & 0xFF != ord('q')):
       ret1, left_frame = l_camera.read()
       ret2, right_frame = r_camera.read()
    
       #our operations on the frame come here
       gray_left = cv2.cvtColor(left_frame, cv2.COLOR_BGR2GRAY)
       gray_right = cv2.cvtColor(right_frame, cv2.COLOR_BGR2GRAY)
       cv2.imshow('left_Webcam', gray_left)
       cv2.imshow('right_Webcam', gray_right)
       stereo = cv2.StereoSGBM_create(minDisparity=1,
           numDisparities=16,
           blockSize=15,
           uniquenessRatio = 10,
           speckleWindowSize = 10,
           speckleRange = 32,
           disp12MaxDiff = 1,
           P1 = 8*3*blockSize**2,
           P2 = 32*3*blockSize**2
        )
        disparity = stereo.compute(gray_left, gray_right)
        disparity = cv2.normalize(disparity, disparity, alpha=0, beta=255,norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)
        cv2.imshow('disparity', disparity)
    
    # When everything done, release the capture
    l_camera.release()
    r_camera.release()
    cv2.destroyAllWindows()
    
  3. 谢谢!

0 个答案:

没有答案