StereoBM方法中视差的投掷错误

时间:2018-09-07 13:38:56

标签: python opencv

我正在使用鱼眼镜头拍摄深度图像。我曾尝试使用StereoSGBM()方法获得深度图,但没有给出理想的结果,但现在我正在尝试使用StereoBM()方法。

stereoMatcher = cv2.StereoBM() preset = 2 ndisparities = 32 WinSize = 5

if not left.grab() or not right.grab():
    print("No more frames")
    break

_, leftFrame = left.retrieve()
#leftFrame = cropHorizontal(leftFrame)
leftHeight, leftWidth = leftFrame.shape[:2]
_, rightFrame = right.retrieve()
#rightFrame = cropHorizontal(rightFrame)
rightHeight, rightWidth = rightFrame.shape[:2]


if (leftWidth, leftHeight) != imageSize:
    print("Left camera has different size than the calibration data")
    break

if (rightWidth, rightHeight) != imageSize:
    print("Right camera has different size than the calibration data")
    break

fixedLeft = cv2.remap(leftFrame, leftMapX, leftMapY,   REMAP_INTERPOLATION)
fixedRight = cv2.remap(rightFrame, rightMapX, rightMapY, REMAP_INTERPOLATION)

grayLeft = cv2.cvtColor(fixedLeft, cv2.COLOR_BGR2GRAY)
grayRight = cv2.cvtColor(fixedRight, cv2.COLOR_BGR2GRAY)

计算时,StereoBM()的函数还需要第三个参数作为视差。我使用

进行了计算
grayLeft = cv2.cvtColor(fixedLeft, cv2.COLOR_BGR2GRAY)
grayRight = cv2.cvtColor(fixedRight, cv2.COLOR_BGR2GRAY)
disparity = stereoMatcher.compute(grayLeft, grayRight)
depth = stereoMatcher.compute(grayLeft, grayRight)


#cv2.imshow('left', fixedLeft)
#cv2.imshow('right', fixedRight)
cv2.imshow('depth', depth / DEPTH_VISUALIZATION_SCALE)

if cv2.waitKey(1) & 0xFF == ord('q'):
    break

left.release() right.release() cv2.destroyAllWindows()

但是它抛出了一个错误:

Traceback (most recent call last):
  File "fisheye_depth.py", line 104, in <module>
    disparity = stereoMatcher.compute(grayLeft, grayRight)
TypeError: Incorrect type of self (must be 'StereoMatcher' or its derivative)

如果有人对此有任何想法,那我在做什么错。让我知道我在计算出算术operator()的差异时犯了什么错误。

0 个答案:

没有答案