aboutsummaryrefslogtreecommitdiff
path: root/helpers.py
diff options
context:
space:
mode:
authorFranoosh <uinarf@autistici.org>2026-05-26 16:32:13 +0200
committerFranoosh <uinarf@autistici.org>2026-05-26 16:32:13 +0200
commit28150dd2c4d03ed844e8d1a5cfc463f5d1f9b45f (patch)
tree2d19117780a7245b2130119ef374cae4e6fb1166 /helpers.py
parenta241288241a9dc300014ecfc93c4f537900f3e9f (diff)
downloadZeroMQ_Video_Streaming-28150dd2c4d03ed844e8d1a5cfc463f5d1f9b45f.tar.gz
ZeroMQ_Video_Streaming-28150dd2c4d03ed844e8d1a5cfc463f5d1f9b45f.tar.bz2
ZeroMQ_Video_Streaming-28150dd2c4d03ed844e8d1a5cfc463f5d1f9b45f.zip
client.cfg : move log dir to /var/log
client.py : use ComputingContoursException and DetectMovementException helpers.py : define ComputingContoursException and DetectMovementException clients.html : small changes webserver.py : minor changes worker.py : log disconnectd from web client on debug, not info
Diffstat (limited to 'helpers.py')
-rw-r--r--helpers.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/helpers.py b/helpers.py
index 8a47415..1ea057b 100644
--- a/helpers.py
+++ b/helpers.py
@@ -96,15 +96,13 @@ def bytes_to_timestamp(byte_data):
def compute_contours(sample_frames):
"""Compute contours between two frames"""
- all_contours = []
frame_0, frame_1 = sample_frames
frame_delta = cv2.absdiff(frame_0, frame_1)
threshold = cv2.threshold(frame_delta, 25, 255, cv2.THRESH_BINARY)[1]
threshold = cv2.dilate(threshold, None, iterations=2)
- contours, _ = cv2.findContours(threshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
- all_contours.extend(contours)
+ contours, _ = cv2.findContours(threshold.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
- return all_contours
+ return contours
def scale_contours(contours, scaling_factor):
@@ -123,7 +121,7 @@ def scale_contours(contours, scaling_factor):
def draw_contours(frame, contours, min_contour_area=500):
"""Draw contours on the frame."""
for contour in contours:
- if cv2.contourArea(contour) > min_contour_area:
+ if cv2.contourArea(contour) >= min_contour_area:
(x, y, w, h) = cv2.boundingRect(contour)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
@@ -272,3 +270,9 @@ def auth_service(context, cert_dir):
auth.start()
auth.configure_curve(location=cert_dir)
zmq.auth.load_certificates(cert_dir)
+
+class ComputingContoursException(Exception):
+ pass
+
+class DetectMovementException(Exception):
+ pass \ No newline at end of file