我正在尝试创建一个带有摄像头输入的视差图,并将摄像头设置在一起 . 由于某种原因,视差图不准确 . 我首先使用棋盘拍摄的照片校准这两个相机并使用此处的代码进行计算https://github.com/bvnayak/stereo_calibration
然后我用前面代码计算的参数进行了整改
R1, R2, P1, P2, Q, roi1, roi2 = cv2.stereoRectify(model['M1'], model['dist1'], model['M2'], model['dist2'],img_shape, model['R'], model['T']) left_map = cv2.initUndistortRectifyMap(model['M1'], model['dist1'], R1, P1, img_shape, cv2.CV_16SC2) right_map = cv2.initUndistortRectifyMap(model['M2'], model['dist2'], R2, P2, img_shape, cv2.CV_16SC2)
然后我重新映射了两张图片
newimgL = cv2.remap(imgL, left_map[0], left_map[1], 4)
newimgR = cv2.remap(imgR, right_map[0], right_map[1], 4)
并使用了block_matcher
block_matcher = cv2.StereoBM_create(numDisparity, blockSize)
disparity = block_matcher.compute(imgL,imgR)
cv2.imshow("camera", disparity/255.)
然而,结果远不止满足 .
The original image from two cameras
有人能告诉我为什么会这样吗?