Add object detection, tracking, mobile notifications, and search to any security camera.
revert
rorycleare5ffc6a88b69
diff --git a/clearcam.py b/clearcam.pyindex 4b2ce2b..d785290 100644--- a/clearcam.py+++ b/clearcam.py@@ -634,7 +634,7 @@ def point_not_in_polygon(coords, poly):return Truedef run_encode_text(return_q, searcher, text):- res = searcher._encode_text(text)+ res = searcher._encode_text(text, realize=True)return_q.put(res)return res@@ -1291,7 +1291,7 @@ class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):for k, v in alerts.items():if time.time() - v.last_det < 60 or not v.is_active(): continueif v.desc is not None and hasattr(v, "desc_emb") and v.desc_emb is not None:- similarity = (v.desc_emb.numpy() @ embedding.T).item()+ similarity = (v.desc_emb @ embedding.T).item()print("sim =",similarity,v.desc,path)if similarity > v.threshold:send_notif(userID, f"Event Detected ({name}: {v.desc})")@@ -1454,3 +1454,4 @@ if __name__ == "__main__":hls_streamer.stop()cam.release()server.shutdown()+diff --git a/clip_search.py b/clip_search.pyindex 51c78e7..d1ba6a2 100644--- a/clip_search.py+++ b/clip_search.py@@ -124,13 +124,15 @@ class CLIPSearch:print(f"\nTotal images loaded: {total_loaded}")- def _encode_text(self, query):+ def _encode_text(self, query, realize=False):tokens = [49406]tokens += self.tokenizer.encode(query)tokens.append(49407)if len(tokens) < 77: tokens += [0] * (77 - len(tokens))tokens = Tensor([tokens])- return encode_text(self.model, tokens)+ text_emb = encode_text(self.model, tokens)+ if realize: return text_emb.numpy()+ return text_embdef search(self, query=None, top_k=10, cam_name=None, timestamp=None, text_embedding=None):if not self.image_embeddings:@@ -208,14 +210,3 @@ def encode_text(model, text):x = x[0][argmax]x = x @ model.text_projectionreturn x / (x * x).sum(axis=-1, keepdim=True).sqrt()--'''-if __name__ == "__main__":- searcher = CLIPSearch()- query = input("\nEnter search query (or 'quit' to exit): ").strip()- results = searcher.search(query, top_k=10)-- print(f"\nTop results for '{query}' (best per object):")- for i, (path, score) in enumerate(results, 1):- print(f"{i}. Score: {score:.3f} - \"{path}\"")-'''