50
50
from pathlib import Path
51
51
import sys
52
52
import signal
53
+ import math
53
54
from stress_test import stress_test , YOLO_LABELS , create_yolo
54
55
55
56
@@ -66,6 +67,8 @@ def socket_type_pair(arg):
66
67
is_thermal = True if type in ['th' , 'thermal' ] else False
67
68
return [socket , is_color , is_tof , is_thermal ]
68
69
70
+ def string_pair (arg ):
71
+ return arg .split ('=' )
69
72
70
73
parser = argparse .ArgumentParser (add_help = False )
71
74
parser .add_argument ('-cams' , '--cameras' , type = socket_type_pair , nargs = '+' ,
@@ -104,6 +107,10 @@ def socket_type_pair(arg):
104
107
help = "Show RGB `preview` stream instead of full size `isp`" )
105
108
parser .add_argument ('-show' , '--show-meta' , action = 'store_true' ,
106
109
help = "List frame metadata (seqno, timestamp, exp, iso etc). Can also toggle with `\`" )
110
+ parser .add_argument ('-misc' , '--misc-controls' , type = string_pair , nargs = '+' ,
111
+ default = [],
112
+ help = "List of miscellaneous camera controls to set initially, "
113
+ "as pairs: key1=value1 key2=value2 ..." )
107
114
108
115
parser .add_argument ('-d' , '--device' , default = "" , type = str ,
109
116
help = "Optional MX ID of the device to connect to." )
@@ -198,8 +205,6 @@ def clamp(num, v0, v1):
198
205
return max (v0 , min (num , v1 ))
199
206
200
207
# Calculates FPS over a moving window, configurable
201
-
202
-
203
208
class FPS :
204
209
def __init__ (self , window_size = 30 ):
205
210
self .dq = collections .deque (maxlen = window_size )
@@ -360,6 +365,15 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
360
365
# cam[c].initialControl.setManualExposure(15000, 400) # exposure [us], iso
361
366
# When set, takes effect after the first 2 frames
362
367
# cam[c].initialControl.setManualWhiteBalance(4000) # light temperature in K, 1000..12000
368
+ # cam[c].initialControl.setAutoExposureLimit(5000) # can also be updated at runtime
369
+ # cam[c].initialControl.setMisc("downsampling-mode", "binning") # default: "scaling"
370
+ # cam[c].initialControl.setMisc("binning-mode", "sum") # default: "avg"
371
+ # cam[c].initialControl.setMisc("manual-exposure-handling", "fast") # default: "default"
372
+ # cam[c].initialControl.setMisc("hdr-exposure-ratio", 4) # enables HDR when set `> 1`, current options: 2, 4, 8
373
+ # cam[c].initialControl.setMisc("hdr-local-tone-weight", 75) # default 75, range 0..100
374
+ # cam[c].initialControl.setMisc("high-conversion-gain", 0) # 1 to enable (default on supported sensors)
375
+ for kvPair in args .misc_controls :
376
+ cam [c ].initialControl .setMisc (* kvPair )
363
377
control .out .link (cam [c ].inputControl )
364
378
if rotate [c ]:
365
379
cam [c ].setImageOrientation (
@@ -534,6 +548,13 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
534
548
chroma_denoise = 0
535
549
control = 'none'
536
550
show = args .show_meta
551
+ high_conversion_gain = 1
552
+ print (args .misc_controls )
553
+ args_misc_dict = dict (args .misc_controls )
554
+
555
+ hdr_exp_ratio = int (math .log2 (float (args_misc_dict .get ('hdr-exposure-ratio' , 1 ))))
556
+ hdr_local_tone_weight = int (32 * float (args_misc_dict .get ('hdr-local-tone-weight' , 0.75 )))
557
+ hdr_on = (hdr_exp_ratio > 0 )
537
558
538
559
jet_custom = cv2 .applyColorMap (
539
560
np .arange (256 , dtype = np .uint8 ), cv2 .COLORMAP_JET )
@@ -664,6 +685,12 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
664
685
elif key == ord ('c' ):
665
686
capture_list = streams .copy ()
666
687
capture_time = time .strftime ('%Y%m%d_%H%M%S' )
688
+ elif key == ord ('h' ):
689
+ high_conversion_gain = 1 - high_conversion_gain
690
+ print ("High conversion gain:" , high_conversion_gain )
691
+ ctrl = dai .CameraControl ()
692
+ ctrl .setMisc ("high-conversion-gain" , high_conversion_gain )
693
+ controlQueue .send (ctrl )
667
694
elif key == ord ('t' ):
668
695
print ("Autofocus trigger (and disable continuous)" )
669
696
ctrl = dai .CameraControl ()
@@ -742,7 +769,7 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
742
769
floodIntensity = 0
743
770
device .setIrFloodLightIntensity (floodIntensity )
744
771
print (f'IR Flood intensity:' , floodIntensity )
745
- elif key >= 0 and chr (key ) in '34567890[]p \\ ;\' ' :
772
+ elif key >= 0 and chr (key ) in '34567890[]\\ ;\' rg ' :
746
773
if key == ord ('3' ):
747
774
control = 'awb_mode'
748
775
elif key == ord ('4' ):
@@ -771,6 +798,11 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
771
798
control = 'chroma_denoise'
772
799
elif key == ord ('p' ):
773
800
control = 'tof_amplitude_min'
801
+ elif key == ord ('r' ) or key == ord ('g' ):
802
+ if hdr_on :
803
+ control = 'hdr_exp_ratio' if key == ord ('r' ) else 'hdr_local_tone_weight'
804
+ else :
805
+ print ("HDR was not enabled, start with `-misc hdr-exposure-ratio=2` or higher to enable" )
774
806
print ("Selected control:" , control )
775
807
elif key in [ord ('-' ), ord ('_' ), ord ('+' ), ord ('=' )]:
776
808
change = 0
@@ -780,7 +812,7 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
780
812
change = 1
781
813
ctrl = dai .CameraControl ()
782
814
if control == 'none' :
783
- print ("Please select a control first using keys 3..9 0 [ ] \\ ; \' " )
815
+ print ("Please select a control first using keys 3..9 0 [ ] \\ ; \' r g " )
784
816
elif control == 'ae_comp' :
785
817
ae_comp = clamp (ae_comp + change , - 9 , 9 )
786
818
print ("Auto exposure compensation:" , ae_comp )
@@ -833,6 +865,16 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
833
865
chroma_denoise = clamp (chroma_denoise + change , 0 , 4 )
834
866
print ("Chroma denoise:" , chroma_denoise )
835
867
ctrl .setChromaDenoise (chroma_denoise )
868
+ elif control == 'hdr_exp_ratio' :
869
+ hdr_exp_ratio = clamp (hdr_exp_ratio + change , 0 , 3 )
870
+ value = pow (2 , hdr_exp_ratio )
871
+ print ("HDR exposure ratio:" , value )
872
+ ctrl .setMisc ("hdr-exposure-ratio" , value )
873
+ elif control == 'hdr_local_tone_weight' :
874
+ hdr_local_tone_weight = clamp (hdr_local_tone_weight + change , 0 , 32 )
875
+ value = hdr_local_tone_weight / 32
876
+ print (f"HDR local tone weight (normalized): { value :.2f} " )
877
+ ctrl .setMisc ("hdr-local-tone-weight" , value )
836
878
controlQueue .send (ctrl )
837
879
838
880
print ()
0 commit comments