Skip to content

Commit bddb42e

Browse files
committed
cam_test.py: some fixes for ToF: -cams rgb,t and other options
1 parent c3ddc39 commit bddb42e

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

utilities/cam_test.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,24 @@ def get(self):
182182
control.setStreamName('control')
183183

184184
cam = {}
185+
tof = {}
185186
xout = {}
186187
xout_raw = {}
187188
streams = []
188189
for c in cam_list:
190+
tofEnableRaw = False
189191
xout[c] = pipeline.createXLinkOut()
190192
xout[c].setStreamName(c)
191193
streams.append(c)
192-
if cam_type_color[c]:
194+
if cam_type_tof[c]:
195+
cam[c] = pipeline.create(dai.node.ColorCamera) # .Camera
196+
if args.tof_raw:
197+
tofEnableRaw = True
198+
else:
199+
tof[c] = pipeline.create(dai.node.ToF)
200+
cam[c].raw.link(tof[c].input)
201+
tof[c].depth.link(xout[c].input)
202+
elif cam_type_color[c]:
193203
cam[c] = pipeline.createColorCamera()
194204
cam[c].setResolution(color_res_opts[args.color_resolution])
195205
cam[c].setIspScale(1, args.isp_downscale)
@@ -215,12 +225,11 @@ def get(self):
215225
if args.isp3afps:
216226
cam[c].setIsp3aFps(args.isp3afps)
217227

218-
if args.enable_raw:
228+
if args.enable_raw or tofEnableRaw:
219229
raw_name = 'raw_' + c
220230
xout_raw[c] = pipeline.create(dai.node.XLinkOut)
221231
xout_raw[c].setStreamName(raw_name)
222-
if args.enable_raw:
223-
streams.append(raw_name)
232+
streams.append(raw_name)
224233
cam[c].raw.link(xout_raw[c].input)
225234
cam[c].setRawOutputPacked(False)
226235

@@ -331,6 +340,14 @@ def exit_cleanly(signum, frame):
331340
fps_capt[c].update(pkt.getTimestamp().total_seconds())
332341
width, height = pkt.getWidth(), pkt.getHeight()
333342
frame = pkt.getCvFrame()
343+
if cam_type_tof[c.split('_')[-1]] and not c.startswith('raw_'):
344+
if args.tof_cm:
345+
# pixels represent `cm`, capped to 255. Value can be checked hovering the mouse
346+
frame = (frame // 10).clip(0, 255).astype(np.uint8)
347+
else:
348+
frame = (frame.view(np.int16).astype(float))
349+
frame = cv2.normalize(frame, frame, alpha=255, beta=0, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)
350+
frame = cv2.applyColorMap(frame, jet_custom)
334351
if show:
335352
txt = f"[{c:5}, {pkt.getSequenceNum():4}] "
336353
txt += f"Exp: {pkt.getExposureTime().total_seconds()*1000:6.3f} ms, "
@@ -361,7 +378,7 @@ def exit_cleanly(signum, frame):
361378
if type == dai.ImgFrame.Type.RAW10: multiplier = (1 << (16-10))
362379
if type == dai.ImgFrame.Type.RAW12: multiplier = (1 << (16-4))
363380
frame = frame * multiplier
364-
# Debayer color for preview/png
381+
# Debayer as color for preview/png
365382
if cam_type_color[c.split('_')[-1]]:
366383
# See this for the ordering, at the end of page:
367384
# https://docs.opencv.org/4.5.1/de/d25/imgproc_color_conversions.html

0 commit comments

Comments
 (0)