45
45
from itertools import cycle
46
46
from pathlib import Path
47
47
import sys
48
- #import cam_test_gui
49
48
import signal
50
49
51
50
52
51
def socket_type_pair (arg ):
53
52
socket , type = arg .split (',' )
54
53
if not (socket in ['rgb' , 'left' , 'right' , 'cama' , 'camb' , 'camc' , 'camd' ]):
55
54
raise ValueError ("" )
56
- if not (type in ['m' , 'mono' , 'c' , 'color' ]):
55
+ if not (type in ['m' , 'mono' , 'c' , 'color' , 't' , 'tof' ]):
57
56
raise ValueError ("" )
58
57
is_color = True if type in ['c' , 'color' ] else False
59
- return [socket , is_color ]
58
+ is_tof = True if type in ['t' , 'tof' ] else False
59
+ return [socket , is_color , is_tof ]
60
60
61
61
62
62
parser = argparse .ArgumentParser ()
63
63
parser .add_argument ('-cams' , '--cameras' , type = socket_type_pair , nargs = '+' ,
64
- default = [['rgb' , True ], ['left' , False ],
65
- ['right' , False ], ['camd' , True ]],
66
- help = "Which camera sockets to enable, and type: c[olor] / m[ono]. "
64
+ default = [['rgb' , True , False ], ['left' , False , False ],
65
+ ['right' , False , False ], ['camd' , True , False ]],
66
+ help = "Which camera sockets to enable, and type: c[olor] / m[ono] / t[of] . "
67
67
"E.g: -cams rgb,m right,c . Default: rgb,c left,m right,m camd,c" )
68
68
parser .add_argument ('-mres' , '--mono-resolution' , type = int , default = 800 , choices = {480 , 400 , 720 , 800 },
69
69
help = "Select mono camera resolution (height). Default: %(default)s" )
@@ -109,15 +109,18 @@ def socket_type_pair(arg):
109
109
import depthai as dai
110
110
111
111
if len (sys .argv ) == 1 :
112
+ import cam_test_gui
112
113
cam_test_gui .main ()
113
114
114
115
cam_list = []
115
116
cam_type_color = {}
117
+ cam_type_tof = {}
116
118
print ("Enabled cameras:" )
117
- for socket , is_color in args .cameras :
119
+ for socket , is_color , is_tof in args .cameras :
118
120
cam_list .append (socket )
119
121
cam_type_color [socket ] = is_color
120
- print (socket .rjust (7 ), ':' , 'color' if is_color else 'mono' )
122
+ cam_type_tof [socket ] = is_tof
123
+ print (socket .rjust (7 ), ':' , 'tof' if is_tof else 'color' if is_color else 'mono' )
121
124
122
125
print ("DepthAI version:" , dai .__version__ )
123
126
print ("DepthAI path:" , dai .__file__ )
@@ -230,7 +233,10 @@ def get(self):
230
233
cam [c ].setResolution (color_res_opts [args .color_resolution ])
231
234
cam [c ].setIspScale (1 , args .isp_downscale )
232
235
# cam[c].initialControl.setManualFocus(85) # TODO
233
- cam [c ].isp .link (xout [c ].input )
236
+ if args .rgb_preview :
237
+ cam [c ].preview .link (xout [c ].input )
238
+ else :
239
+ cam [c ].isp .link (xout [c ].input )
234
240
else :
235
241
cam [c ] = pipeline .createMonoCamera ()
236
242
cam [c ].setResolution (mono_res_opts [args .mono_resolution ])
@@ -352,7 +358,9 @@ def exit_cleanly(signum, frame):
352
358
chroma_denoise = 0
353
359
control = 'none'
354
360
show = False
355
- tof_amp_min = tofConfig .depthParams .minimumAmplitude
361
+
362
+ jet_custom = cv2 .applyColorMap (np .arange (256 , dtype = np .uint8 ), cv2 .COLORMAP_JET )
363
+ jet_custom [0 ] = [0 , 0 , 0 ]
356
364
357
365
print ("Cam:" , * [' ' + c .ljust (8 )
358
366
for c in cam_list ], "[host | capture timestamp]" )
@@ -370,7 +378,8 @@ def exit_cleanly(signum, frame):
370
378
fps_capt [c ].update (pkt .getTimestamp ().total_seconds ())
371
379
width , height = pkt .getWidth (), pkt .getHeight ()
372
380
frame = pkt .getCvFrame ()
373
- if cam_type_tof [c .split ('_' )[- 1 ]] and not (c .startswith ('raw_' ) or c .startswith ('tof_amplitude_' )):
381
+ cam_skt = c .split ('_' )[- 1 ]
382
+ if cam_type_tof [cam_skt ] and not (c .startswith ('raw_' ) or c .startswith ('tof_amplitude_' )):
374
383
if args .tof_cm :
375
384
# pixels represent `cm`, capped to 255. Value can be checked hovering the mouse
376
385
frame = (frame // 10 ).clip (0 , 255 ).astype (np .uint8 )
@@ -387,7 +396,7 @@ def exit_cleanly(signum, frame):
387
396
print (txt )
388
397
capture = c in capture_list
389
398
if capture :
390
- capture_file_info = ('capture_' + c + '_' + cam_name [c ]
399
+ capture_file_info = ('capture_' + c + '_' + cam_name [cam_socket_opts [ cam_skt ]. name ]
391
400
+ '_' + str (width ) + 'x' + str (height )
392
401
+ '_exp_' + str (int (pkt .getExposureTime ().total_seconds ()* 1e6 ))
393
402
+ '_iso_' + str (pkt .getSensitivity ())
@@ -409,7 +418,7 @@ def exit_cleanly(signum, frame):
409
418
if type == dai .ImgFrame .Type .RAW12 : multiplier = (1 << (16 - 4 ))
410
419
frame = frame * multiplier
411
420
# Debayer as color for preview/png
412
- if cam_type_color [c . split ( '_' )[ - 1 ] ]:
421
+ if cam_type_color [cam_skt ]:
413
422
# See this for the ordering, at the end of page:
414
423
# https://docs.opencv.org/4.5.1/de/d25/imgproc_color_conversions.html
415
424
# TODO add bayer order to ImgFrame getType()
@@ -441,12 +450,12 @@ def exit_cleanly(signum, frame):
441
450
elif key == ord ('c' ):
442
451
capture_list = streams .copy ()
443
452
capture_time = time .strftime ('%Y%m%d_%H%M%S' )
444
- elif key == ord ('g' ):
453
+ elif key == ord ('g' ) and tof :
445
454
f_mod = dai .RawToFConfig .DepthParams .TypeFMod .MAX if tofConfig .depthParams .freqModUsed == dai .RawToFConfig .DepthParams .TypeFMod .MIN else dai .RawToFConfig .DepthParams .TypeFMod .MIN
446
455
print ("ToF toggling f_mod value to:" , f_mod )
447
456
tofConfig .depthParams .freqModUsed = f_mod
448
457
tofCfgQueue .send (tofConfig )
449
- elif key == ord ('h' ):
458
+ elif key == ord ('h' ) and tof :
450
459
tofConfig .depthParams .avgPhaseShuffle = not tofConfig .depthParams .avgPhaseShuffle
451
460
print ("ToF toggling avgPhaseShuffle value to:" , tofConfig .depthParams .avgPhaseShuffle )
452
461
tofCfgQueue .send (tofConfig )
@@ -597,7 +606,7 @@ def exit_cleanly(signum, frame):
597
606
chroma_denoise = clamp (chroma_denoise + change , 0 , 4 )
598
607
print ("Chroma denoise:" , chroma_denoise )
599
608
ctrl .setChromaDenoise (chroma_denoise )
600
- elif control == 'tof_amplitude_min' :
609
+ elif control == 'tof_amplitude_min' and tof :
601
610
amp_min = clamp (tofConfig .depthParams .minimumAmplitude + change , 0 , 50 )
602
611
print ("Setting min amplitude(confidence) to:" , amp_min )
603
612
tofConfig .depthParams .minimumAmplitude = amp_min
0 commit comments