5555manip .out .link (nn .input )
5656
5757# Create outputs
58- depthOut = pipeline .createXLinkOut ()
59- depthOut .setStreamName ("depth" )
60-
61- stereo .disparity .link (depthOut .input )
58+ disparityOut = pipeline .createXLinkOut ()
59+ disparityOut .setStreamName ("disparity" )
60+ stereo .disparity .link (disparityOut .input )
6261
6362xoutRight = pipeline .createXLinkOut ()
6463xoutRight .setStreamName ("rectifiedRight" )
7978
8079 # Output queues will be used to get the grayscale / depth frames and nn data from the outputs defined above
8180 qRight = device .getOutputQueue ("rectifiedRight" , maxSize = 4 , blocking = False )
82- qDepth = device .getOutputQueue ("depth " , maxSize = 4 , blocking = False )
81+ qDisparity = device .getOutputQueue ("disparity " , maxSize = 4 , blocking = False )
8382 qDet = device .getOutputQueue ("nn" , maxSize = 4 , blocking = False )
8483
8584 rightFrame = None
@@ -104,11 +103,12 @@ def show(name, frame):
104103 # Show the frame
105104 cv2 .imshow (name , frame )
106105
106+ disparity_multiplier = 255 / 95 # Disparity range is 0..95
107107 while True :
108108 # Instead of get (blocking), we use tryGet (nonblocking) which will return the available data or None otherwise
109109 inRight = qRight .tryGet ()
110110 inDet = qDet .tryGet ()
111- inDepth = qDepth .tryGet ()
111+ inDisparity = qDisparity .tryGet ()
112112
113113 if inRight is not None :
114114 rightFrame = inRight .getCvFrame ()
@@ -124,13 +124,13 @@ def show(name, frame):
124124 detection .xmin = 1 - detection .xmax
125125 detection .xmax = 1 - swap
126126
127- if inDepth is not None :
128- # Frame is transformed, the color map will be applied to highlight the depth info
127+ if inDisparity is not None :
128+ # Frame is transformed, normalized, and color map will be applied to highlight the depth info
129+ disparityFrame = inDisparity .getFrame ()
130+ disparityFrame = (disparityFrame * disparity_multiplier ).astype (np .uint8 )
129131 # Available color maps: https://docs.opencv.org/3.4/d3/d50/group__imgproc__colormap.html
130- depthFrame = cv2 .applyColorMap (inDepth .getFrame (), cv2 .COLORMAP_JET )
131-
132- if depthFrame is not None :
133- show ("depth" , depthFrame )
132+ disparityFrame = cv2 .applyColorMap (disparityFrame , cv2 .COLORMAP_JET )
133+ show ("disparity" , disparityFrame )
134134
135135 if rightFrame is not None :
136136 show ("rectified right" , rightFrame )
0 commit comments