4545from itertools import cycle
4646from pathlib import Path
4747import sys
48- #import cam_test_gui
4948import signal
5049
5150
5251def socket_type_pair (arg ):
5352 socket , type = arg .split (',' )
5453 if not (socket in ['rgb' , 'left' , 'right' , 'cama' , 'camb' , 'camc' , 'camd' ]):
5554 raise ValueError ("" )
56- if not (type in ['m' , 'mono' , 'c' , 'color' ]):
55+ if not (type in ['m' , 'mono' , 'c' , 'color' , 't' , 'tof' ]):
5756 raise ValueError ("" )
5857 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 ]
6060
6161
6262parser = argparse .ArgumentParser ()
6363parser .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] . "
6767 "E.g: -cams rgb,m right,c . Default: rgb,c left,m right,m camd,c" )
6868parser .add_argument ('-mres' , '--mono-resolution' , type = int , default = 800 , choices = {480 , 400 , 720 , 800 },
6969 help = "Select mono camera resolution (height). Default: %(default)s" )
@@ -109,15 +109,18 @@ def socket_type_pair(arg):
109109import depthai as dai
110110
111111if len (sys .argv ) == 1 :
112+ import cam_test_gui
112113 cam_test_gui .main ()
113114
114115cam_list = []
115116cam_type_color = {}
117+ cam_type_tof = {}
116118print ("Enabled cameras:" )
117- for socket , is_color in args .cameras :
119+ for socket , is_color , is_tof in args .cameras :
118120 cam_list .append (socket )
119121 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' )
121124
122125print ("DepthAI version:" , dai .__version__ )
123126print ("DepthAI path:" , dai .__file__ )
@@ -230,7 +233,10 @@ def get(self):
230233 cam [c ].setResolution (color_res_opts [args .color_resolution ])
231234 cam [c ].setIspScale (1 , args .isp_downscale )
232235 # 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 )
234240 else :
235241 cam [c ] = pipeline .createMonoCamera ()
236242 cam [c ].setResolution (mono_res_opts [args .mono_resolution ])
@@ -352,7 +358,9 @@ def exit_cleanly(signum, frame):
352358 chroma_denoise = 0
353359 control = 'none'
354360 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 ]
356364
357365 print ("Cam:" , * [' ' + c .ljust (8 )
358366 for c in cam_list ], "[host | capture timestamp]" )
@@ -370,7 +378,8 @@ def exit_cleanly(signum, frame):
370378 fps_capt [c ].update (pkt .getTimestamp ().total_seconds ())
371379 width , height = pkt .getWidth (), pkt .getHeight ()
372380 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_' )):
374383 if args .tof_cm :
375384 # pixels represent `cm`, capped to 255. Value can be checked hovering the mouse
376385 frame = (frame // 10 ).clip (0 , 255 ).astype (np .uint8 )
@@ -387,7 +396,7 @@ def exit_cleanly(signum, frame):
387396 print (txt )
388397 capture = c in capture_list
389398 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 ]
391400 + '_' + str (width ) + 'x' + str (height )
392401 + '_exp_' + str (int (pkt .getExposureTime ().total_seconds ()* 1e6 ))
393402 + '_iso_' + str (pkt .getSensitivity ())
@@ -409,7 +418,7 @@ def exit_cleanly(signum, frame):
409418 if type == dai .ImgFrame .Type .RAW12 : multiplier = (1 << (16 - 4 ))
410419 frame = frame * multiplier
411420 # Debayer as color for preview/png
412- if cam_type_color [c . split ( '_' )[ - 1 ] ]:
421+ if cam_type_color [cam_skt ]:
413422 # See this for the ordering, at the end of page:
414423 # https://docs.opencv.org/4.5.1/de/d25/imgproc_color_conversions.html
415424 # TODO add bayer order to ImgFrame getType()
@@ -441,12 +450,12 @@ def exit_cleanly(signum, frame):
441450 elif key == ord ('c' ):
442451 capture_list = streams .copy ()
443452 capture_time = time .strftime ('%Y%m%d_%H%M%S' )
444- elif key == ord ('g' ):
453+ elif key == ord ('g' ) and tof :
445454 f_mod = dai .RawToFConfig .DepthParams .TypeFMod .MAX if tofConfig .depthParams .freqModUsed == dai .RawToFConfig .DepthParams .TypeFMod .MIN else dai .RawToFConfig .DepthParams .TypeFMod .MIN
446455 print ("ToF toggling f_mod value to:" , f_mod )
447456 tofConfig .depthParams .freqModUsed = f_mod
448457 tofCfgQueue .send (tofConfig )
449- elif key == ord ('h' ):
458+ elif key == ord ('h' ) and tof :
450459 tofConfig .depthParams .avgPhaseShuffle = not tofConfig .depthParams .avgPhaseShuffle
451460 print ("ToF toggling avgPhaseShuffle value to:" , tofConfig .depthParams .avgPhaseShuffle )
452461 tofCfgQueue .send (tofConfig )
@@ -597,7 +606,7 @@ def exit_cleanly(signum, frame):
597606 chroma_denoise = clamp (chroma_denoise + change , 0 , 4 )
598607 print ("Chroma denoise:" , chroma_denoise )
599608 ctrl .setChromaDenoise (chroma_denoise )
600- elif control == 'tof_amplitude_min' :
609+ elif control == 'tof_amplitude_min' and tof :
601610 amp_min = clamp (tofConfig .depthParams .minimumAmplitude + change , 0 , 50 )
602611 print ("Setting min amplitude(confidence) to:" , amp_min )
603612 tofConfig .depthParams .minimumAmplitude = amp_min
0 commit comments