Add object detection, tracking, mobile notifications, and search to any security camera.
add custom url notif stuff
Rory Cleardb5d8dec5414
diff --git a/clearcam.py b/clearcam.pyindex 68d3c14..0999b01 100644--- a/clearcam.py+++ b/clearcam.py@@ -480,12 +480,12 @@ class VideoCapture:self.filename[cam_name] = filepath / f"{ts}_notif.jpg"if global_settings.use_notifs() is not None and not self.vod[cam_name] and alert.is_notif:title = f"Event Detected ({cam_name})"- threading.Thread(target=send_notif, args=(global_settings.userID,title,None), daemon=True).start()+ threading.Thread(target=send_notif, args=(global_settings.userID,title,None,global_settings.server_url), daemon=True).start()if global_settings.use_qwen: # extra notif if qwen# use frames before last, only one reset needed, must convert to RGBfor i in range(len(self.last_frames[cam_name])-1): qwen.generate(image=cv2.cvtColor(self.last_frames[cam_name][i], cv2.COLOR_BGR2RGB), reset=True if i==0 else False)text = qwen.generate(prompt=global_settings.qwen_prompt, image=cv2.cvtColor(cv2.imread(self.filename[cam_name]), cv2.COLOR_BGR2RGB), reset=False) # must reset or run out of context- threading.Thread(target=send_notif, args=(global_settings.userID,f"AI Summary ({cam_name}):",text), daemon=True).start()+ threading.Thread(target=send_notif, args=(global_settings.userID,f"AI Summary ({cam_name}):",text,global_settings.server_url), daemon=True).start()if global_settings.clearcam_user(): threading.Thread(target=export_and_upload, kwargs={"cam_name": cam_name, "thumbnail": self.filename[cam_name], "userID": global_settings.userID, "key": global_settings.key, "start": ts}, daemon=True).start()self.last_det[cam_name] = time.time()alert.last_det = time.time()@@ -1292,7 +1292,7 @@ def clip_latest_img(img):similarity = (v.desc_emb @ emb.T).item()print("sim =",similarity,v.desc,object_queue[0])if similarity > v.threshold:- send_notif(global_settings.userID, f"Event Detected ({cam_name}: {v.desc})")+ send_notif(global_settings.userID, f"Event Detected ({cam_name}: {v.desc})",None,global_settings.server_url)alerts[k].last_det = time.time()database.run_put("alerts", cam_name, alerts[k], k)if global_settings.clearcam_user():diff --git a/utils/helpers.py b/utils/helpers.pyindex db4f80c..b651ef2 100644--- a/utils/helpers.py+++ b/utils/helpers.py@@ -15,8 +15,9 @@ import numpy as npBASE_DIR = Path(__file__).parent.parent / "data"from tinygrad import Tensor, TinyJit-def send_notif(session_token: str, text=None, body_text=None):- host = "clearcam.org" # todo, use settings!+def send_notif(session_token: str, text=None, body_text=None, host="https://clearcam.org"):+ https = host.startswith("https://")+ if host.startswith("http"): host = host[host.index("//")+2:] # remove https:// / http:endpoint = "/send" #/testboundary = f"Boundary-{uuid.uuid4()}"content_type = f"multipart/form-data; boundary={boundary}"@@ -44,7 +45,7 @@ def send_notif(session_token: str, text=None, body_text=None):])body = "\r\n".join(lines).encode("utf-8")- conn = http.client.HTTPSConnection(host)+ conn = http.client.HTTPSConnection(host) if https else http.client.HTTPConnection(host)headers = {"Content-Type": content_type, "Content-Length": str(len(body))}try:conn.request("POST", endpoint, body, headers)