Skip to content

Commit 3801d1b

Browse files
author
Dave
committed
Configuration option to turn off tracking boxes on web preview and Video recording. Configuration option to disarm the waterpistol when in auto mode.
1 parent 86dd33b commit 3801d1b

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

main.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ def load_configuration():
8383
DELETE_CONVERTED_FILES = config.DELETE_CONVERTED_FILES
8484
ALPHA = config.ALPHA
8585
FADE_FRAMES = config.FADE_FRAMES
86+
DISPLAY_BOXES_VIDEO = config.DISPLAY_BOXES_VIDEO
87+
DISPLAY_BOXES_PREVIEW = config.DISPLAY_BOXES_PREVIEW
88+
WATER_PISTOL_ARMED = config.WATER_PISTOL_ARMED
89+
8690

8791
#Variable for smoothed boxes
8892
smoothed_boxes = {} # { category_id: { "box": (x, y, w, h), "no_update_count": 0 } }
@@ -964,7 +968,9 @@ def do_frame_callback(request):
964968

965969
if is_acquired and not was_acquired and auto_mode:
966970
recording_requested = True
967-
water_pistol.start()
971+
if WATER_PISTOL_ARMED:
972+
water_pistol.start()
973+
968974
elif was_acquired and not is_acquired and auto_mode:
969975
recording_stop_requested = True
970976
water_pistol.stop()
@@ -994,8 +1000,9 @@ def do_frame_callback(request):
9941000
pan_tilt.set_target_by_pixels(offset_x, offset_y)
9951001

9961002

997-
# 5) Draw bounding boxes on main (1:1) and lores (scaled)
1003+
# 5) Draw bounding boxes on main (1:1)
9981004
inside_box = False
1005+
9991006
if recording_manager.recording and len(smoothed_dets) > 0:
10001007
main_w, main_h = picam2.stream_configuration("main")["size"]
10011008
cx = main_w // 2
@@ -1005,18 +1012,19 @@ def do_frame_callback(request):
10051012
if bx <= cx <= (bx + bw) and by <= cy <= (by + bh):
10061013
inside_box = True
10071014
break
1008-
1009-
with MappedArray(request, "main") as m:
1010-
main_array = m.array
1011-
draw_detections_on_frame(
1012-
main_array,
1013-
smoothed_dets, # pass the "smoothed" list
1014-
intrinsics,
1015-
recording_manager.recording,
1016-
inside_box,
1017-
scale_x=1.0,
1018-
scale_y=1.0
1019-
)
1015+
if DISPLAY_BOXES_VIDEO:
1016+
with MappedArray(request, "main") as m:
1017+
main_array = m.array
1018+
draw_detections_on_frame(
1019+
main_array,
1020+
smoothed_dets, # pass the "smoothed" list
1021+
intrinsics,
1022+
recording_manager.recording,
1023+
inside_box,
1024+
scale_x=1.0,
1025+
scale_y=1.0
1026+
)
1027+
# 6) Draw bounding boxes on lowres (scaled)
10201028

10211029
with MappedArray(request, "lores") as lores_m:
10221030
lores_frame = cv2.cvtColor(lores_m.array, cv2.COLOR_YUV2BGR_I420)
@@ -1026,15 +1034,16 @@ def do_frame_callback(request):
10261034
sx = lores_w / float(main_w)
10271035
sy = lores_h / float(main_h)
10281036

1029-
draw_detections_on_frame(
1030-
lores_frame,
1031-
smoothed_dets, # pass the smoothed list
1032-
intrinsics,
1033-
recording_manager.recording,
1034-
inside_box,
1035-
scale_x=sx,
1036-
scale_y=sy
1037-
)
1037+
if DISPLAY_BOXES_PREVIEW:
1038+
draw_detections_on_frame(
1039+
lores_frame,
1040+
smoothed_dets, # pass the smoothed list
1041+
intrinsics,
1042+
recording_manager.recording,
1043+
inside_box,
1044+
scale_x=sx,
1045+
scale_y=sy
1046+
)
10381047
latest_frame = lores_frame.copy()
10391048

10401049

my_configuration.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
# Zone around center in which we do NOT move (pixels) when tracking, so if the we are within dead_zone (in the centre of the image) we wont move any further
4040
DEAD_ZONE = 60
4141

42+
#Show bounding boxes
43+
DISPLAY_BOXES_VIDEO = True
44+
DISPLAY_BOXES_PREVIEW = True
45+
4246
#Smoothing
4347
ALPHA = 1.0 # blending factor: 0.3..0.7 typical
4448
FADE_FRAMES = 3 # how many consecutive frames with no detection before we remove the box
@@ -51,6 +55,9 @@
5155
MOVE_STEPS = 1
5256
MOVE_STEP_DELAY = 0.00
5357

58+
# Fire water pistol on detections
59+
WATER_PISTOL_ARMED = True
60+
5461
#Picamera settings
5562

5663
SHOW_PREVIEW = False # Set to false in headless mode, if running locally on PI setting to True will show the live preview in a window

0 commit comments

Comments
 (0)