Add object detection, tracking, mobile notifications, and search to any security camera.
non blocking upload
Rory Cleared68bf83cd64
diff --git a/experimental/clearcam_rtsp.py b/experimental/clearcam_rtsp.pyindex 0f9090c..34258ae 100644--- a/experimental/clearcam_rtsp.py+++ b/experimental/clearcam_rtsp.py@@ -449,13 +449,18 @@ class VideoCapture:if time.time() - last_det >= 60: # once per min for nowsend_det = Trueprint("DETECTED") # todo, magic 5, change of 5 over 10 frames = detection+ os.makedirs("event_images", exist_ok=True)+ timestamp = datetime.now().strftime("%Y-%m-%d_%H:%M:%S")+ filename = f"event_images/frame_{timestamp}.jpg"+ cv2.imwrite(filename, self.annotated_frame)+ if userID is not None: send_notif(userID)last_det = time.time()if (send_det and userID is not None) and time.time() - last_det >= 15: #send 15ish second clip afteros.makedirs("event_clips", exist_ok=True)mp4_filename = f"event_clips/{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.mp4"self.streamer.export_last_segments(Path(mp4_filename))encrypt_file(Path(mp4_filename), Path(f"""{mp4_filename}.aes"""), key)- upload_file(file_path=Path(f"""{mp4_filename}.aes"""),session_token=userID)+ threading.Thread(target=upload_file, args=(Path(f"""{mp4_filename}.aes"""), userID), daemon=True).start()send_det = Falsewith self.lock:self.raw_frame = frame.copy()@@ -707,30 +712,35 @@ def schedule_daily_restart(hls_streamer, restart_time):hls_streamer.start()def send_notif(session_token: str):- host = "www.rors.ai"- endpoint = "/test/send"- boundary = f"Boundary-{uuid.uuid4()}"- content_type = f"multipart/form-data; boundary={boundary}"- lines = [- f"--{boundary}",- 'Content-Disposition: form-data; name="session_token"',- "",- session_token,- f"--{boundary}--",- ""- ]- body = "\r\n".join(lines).encode("utf-8")- conn = http.client.HTTPSConnection(host)- headers = { "Content-Type": content_type, "Content-Length": str(len(body))}- try:- conn.request("POST", endpoint, body, headers)- response = conn.getresponse()- print(f"Status: {response.status} {response.reason}")- print(response.read().decode())- except Exception as e:- print(f"Error sending session token: {e}")- finally:- conn.close()+ def _send():+ host = "www.rors.ai"+ endpoint = "/test/send"+ boundary = f"Boundary-{uuid.uuid4()}"+ content_type = f"multipart/form-data; boundary={boundary}"+ lines = [+ f"--{boundary}",+ 'Content-Disposition: form-data; name="session_token"',+ "",+ session_token,+ f"--{boundary}--",+ ""+ ]+ body = "\r\n".join(lines).encode("utf-8")+ conn = http.client.HTTPSConnection(host)+ headers = {"Content-Type": content_type, "Content-Length": str(len(body))}+ try:+ conn.request("POST", endpoint, body, headers)+ response = conn.getresponse()+ print(f"Status: {response.status} {response.reason}")+ print(response.read().decode())+ except Exception as e:+ print(f"Error sending session token: {e}")+ finally:+ conn.close()++ # Run the actual request in a daemon thread+ threading.Thread(target=_send, daemon=True).start()+import aesMAGIC_NUMBER = 0x4D41474943