I am trying to get the depth map of two stereo images but error ‘cv2.cv2’ has no attribute ‘STEREO_BM_BASIC_PRESET’ occurred. the code:
JavaScript
x
14
14
1
import cv2
2
import numpy as np
3
from matplotlib import pyplot as plt
4
# Convert to depth image
5
6
imgL = cv2.imread('D:BooksPav ManPICSR.jpg',0)
7
imgR = cv2.imread('D:BooksPav ManPICSL.jpg',0)
8
9
stereo = cv2.StereoBM(cv2.STEREO_BM_BASIC_PRESET,ndisparities=16, SADWindowSize=15)
10
disparity = stereo.compute(imgL,imgR)
11
plt.imshow(disparity,'gray')
12
plt.show()
13
#-------------------
14
Advertisement
Answer
solved worked with OpenCV 4.
JavaScript
1
16
16
1
import cv2
2
import numpy as np
3
from matplotlib import pyplot as plt
4
# Convert to depth image
5
6
imgL = cv2.imread('D:BooksPav ManPICSR.jpg',0)
7
imgR = cv2.imread('D:BooksPav ManPICSL.jpg',0)
8
9
stereo = cv2.StereoBM_create(numDisparities=16, blockSize=15)
10
11
disparity = stereo.compute(imgL,imgR)
12
13
plt.imshow(disparity,'gray')
14
15
plt.show()
16