Skip to content

Commit 75f9827

Browse files
committed
cam_test: add B key to toggle HDR exposure base,
RVC2 FW CameraControl: setMisc add "hdr-exposure-base": "long" (default), "middle" option. Operation: - from the BASE exposure (AE or user), with the default "long": -- long = BASE -- middle = BASE / hdr-exposure-ratio -- short = BASE / hdr-exposure-ratio / hdr-exposure-ratio - with the option "middle": -- long = BASE * hdr-exposure-ratio -- middle = BASE -- short = BASE / hdr-exposure-ratio Allow "hdr-exposure-ratio" = 1, at runtime only (not initialControl), to disable HDR and compare the effect. Fix a bug in handling "hdr-local-tone-weight" control.
1 parent 25bfe36 commit 75f9827

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

depthai-core

utilities/cam_test.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
276276
cam_type_thermal[socket] = is_thermal
277277
print(socket.rjust(7), ':', 'tof' if is_tof else 'color' if is_color else 'thermal' if is_thermal else 'mono')
278278

279+
print('misc controls:', args.misc_controls)
280+
args_misc_dict = dict(args.misc_controls)
281+
282+
hdr_exp_ratio = int(math.log2(float(args_misc_dict.get('hdr-exposure-ratio', 1))))
283+
hdr_exp_base = args_misc_dict.get('hdr-exposure-base', 'long')
284+
hdr_local_tone_weight = int(32 * float(args_misc_dict.get('hdr-local-tone-weight', 0.75)))
285+
hdr_on = (hdr_exp_ratio > 0)
286+
if hdr_on and args.fps > 10:
287+
print('WARNING: HDR enabled for IMX582/IMX586, limiting FPS to 10')
288+
args.fps = 10
289+
279290
# Start defining a pipeline
280291
pipeline = dai.Pipeline()
281292
# Uncomment to get better throughput
@@ -370,7 +381,8 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
370381
# cam[c].initialControl.setMisc("binning-mode", "sum") # default: "avg"
371382
# cam[c].initialControl.setMisc("manual-exposure-handling", "fast") # default: "default"
372383
# 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
384+
# cam[c].initialControl.setMisc("hdr-exposure-base", "middle") # default "long"
385+
# cam[c].initialControl.setMisc("hdr-local-tone-weight", 0.75) # default 0.75, range 0..1
374386
# cam[c].initialControl.setMisc("high-conversion-gain", 0) # 1 to enable (default on supported sensors)
375387
for kvPair in args.misc_controls:
376388
cam[c].initialControl.setMisc(*kvPair)
@@ -549,12 +561,6 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
549561
control = 'none'
550562
show = args.show_meta
551563
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)
558564

559565
jet_custom = cv2.applyColorMap(
560566
np.arange(256, dtype=np.uint8), cv2.COLORMAP_JET)
@@ -756,6 +762,15 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
756762
ctrl = dai.CameraControl()
757763
ctrl.setAutoExposureLock(ae_lock)
758764
controlQueue.send(ctrl)
765+
elif key == ord('b'):
766+
if hdr_on:
767+
hdr_exp_base = 'middle' if hdr_exp_base == 'long' else 'long'
768+
print(f"HDR exposure base: {hdr_exp_base}")
769+
ctrl = dai.CameraControl()
770+
ctrl.setMisc("hdr-exposure-base", hdr_exp_base)
771+
controlQueue.send(ctrl)
772+
else:
773+
print("HDR was not enabled, start with `-misc hdr-exposure-ratio=2` or higher to enable")
759774
elif key == ord('a'):
760775
dotIntensity = dotIntensity - DOT_STEP
761776
if dotIntensity < 0:
@@ -879,7 +894,7 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
879894
elif control == 'hdr_exp_ratio':
880895
hdr_exp_ratio = clamp(hdr_exp_ratio + change, 0, 3)
881896
value = pow(2, hdr_exp_ratio)
882-
print("HDR exposure ratio:", value)
897+
print("HDR exposure ratio:", value, '(HDR disabled)' if value == 1 else '')
883898
ctrl.setMisc("hdr-exposure-ratio", value)
884899
elif control == 'hdr_local_tone_weight':
885900
hdr_local_tone_weight = clamp(hdr_local_tone_weight + change, 0, 32)

0 commit comments

Comments
 (0)