-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisparity_SGBM.py
52 lines (42 loc) · 1.53 KB
/
Disparity_SGBM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import cv2
from matplotlib import pyplot as plt
import numpy as np
import time
start = time.clock()
# disparity settings
min_disp = 32
num_disp = 112 - min_disp
stereo = cv2.StereoSGBM_create(numDisparities=16, blockSize=15)
# do it
imgL = cv2.imread('output/calibration_binocular/rectifiedleft04.jpg', 0)
imgR = cv2.imread('output/calibration_binocular/rectifiedright04.jpg', 0)
# disparity = stereo.compute(imgL, imgR)
disparity = stereo.compute(imgL, imgR).astype(np.float32) / 16.0
print("========================Left Disparity=========================")
print(disparity)
plt.imshow(disparity, 'gray')
plt.savefig('output/Disparity/SGBMleft104.jpg')
plt.show()
print("========================Left Depth=========================")
disparity = (disparity-min_disp)/num_disp
print(disparity)
plt.imshow(disparity, 'gray')
plt.savefig('output/Depth/SGBMleft104.jpg')
plt.show()
# cv2.imwrite('output/Disparity/SGBMleft04.jpg', disparity)
# disparity = stereo.compute(imgL, imgR)
disparity = stereo.compute(imgR, imgL).astype(np.float32) / 16.0
print("========================Right Disparity=========================")
print(disparity)
plt.imshow(disparity, 'gray')
plt.savefig('output/Disparity/SGBMright104.jpg')
plt.show()
print("========================Right Depth=========================")
disparity = (disparity-min_disp)/num_disp
print(disparity)
plt.imshow(disparity, 'gray')
plt.savefig('output/Depth/SGBMright104.jpg')
plt.show()
# cv2.imwrite('output/Disparity/SGBMright04.jpg', disparity)
end = time.clock()
print("time:" + str(end - start))