diff options
Diffstat (limited to 'helpers.py')
| -rw-r--r-- | helpers.py | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -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 |
