-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdepth.py
More file actions
22 lines (17 loc) · 711 Bytes
/
depth.py
File metadata and controls
22 lines (17 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import numpy as np
import cv2
# Load the left and right images in gray scale
imgLeft = cv2.imread('C:\\Users\\Angad Bajwa\\Downloads\\tsukuba_l.png', 0)
imgRight = cv2.imread('C:\\Users\\Angad Bajwa\\Downloads\\tsukuba_r.png', 0)
# Initialize the stereo block matching object
stereo = cv2.StereoBM_create(numDisparities=32, blockSize=13)
# Compute the disparity image
disparity = stereo.compute(imgLeft, imgRight)
# Normalize the image for representation
min = disparity.min()
max = disparity.max()
disparity = np.uint8(255 * (disparity - min) / (max - min))
# Display the result
cv2.imshow('disparity', np.hstack((imgLeft, imgRight, disparity)))
cv2.waitKey(0)
cv2.destroyAllWindows()