Hi @spnsingh
The way you have divided your blocks opens the code up for a bunch of errors. Please put the pipeline related code in its own cell.
You can put the rest in a separate cell but keep in mind that each time you use dai.Device(), the device will be opened and run.
Call the device with this code.
# Connect to device and start pipeline
with dai.Device(pipeline) as device:
print('Connected cameras:', device.getConnectedCameraFeatures())
q = device.getOutputQueue(name="depth")
while True:
imgFrame = q.get() # blocking call, will wait until a new data has arrived
depth_map = imgFrame.getFrame()
# Colorize the depth frame to jet colormap
depth_downscaled = depth_map[::4]
non_zero_depth = depth_downscaled[depth_downscaled != 0] # Remove invalid depth values
if len(non_zero_depth) == 0:
min_depth, max_depth = 0, 0
else:
min_depth = np.percentile(non_zero_depth, 3)
max_depth = np.percentile(non_zero_depth, 97)
depth_colorized = np.interp(depth_map, (min_depth, max_depth), (0, 255)).astype(np.uint8)
depth_colorized = cv2.applyColorMap(depth_colorized, cv2.COLORMAP_JET)
cv2.imshow("Colorized depth", depth_colorized)
if cv2.waitKey(1) == ord('q'):
break
Thanks,
Jaka