Skip to content

Commit

Permalink
fix glitch in detection
Browse files Browse the repository at this point in the history
  • Loading branch information
isaric committed Dec 26, 2023
1 parent 3458f18 commit 0d88558
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "python",
"request": "attach",
"connect": {
"host": "10.66.66.6",
"host": "localhost",
"port": 5678
},
"pathMappings": [
Expand Down
27 changes: 15 additions & 12 deletions face_recog/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,32 @@ def _get_embeddings(self, image):
return face_recognition.face_encodings(image, faces), faces

def _compare_with_existing(self, existing, detected, faces):
if existing.collection.count_documents({}) == 0:
if len(existing) == 0:
logging.info("No existing embeddings found")
return [], tuple(zip(detected, faces))

recognized = []
unknown = []

for e in existing:
for d in detected:
box = faces[detected.index(d)]
if self._is_match(e, d):
name = e["name"]
logging.info(f"Found match - {name}")
recognized.append((name, box))
else:
unknown.append((d,box))
for d in detected:
box = faces[detected.index(d)]
e, m = self._is_match(existing, d)
if m:
name = e["name"]
logging.info(f"Found match - {name}")
recognized.append((name, box))
else:
unknown.append((d,box))

return recognized, unknown


def _is_match(self, existing, detected):
match = face_recognition.compare_faces([existing['embedding']], detected)
return True in match
match = face_recognition.compare_faces([e["embedding"] for e in existing], detected)
for i,m in enumerate(match):
if m:
return existing[i], True
return None, False

def _save_embeddings(self, embeddings):
for embedding, _ in embeddings:
Expand Down
2 changes: 1 addition & 1 deletion mongo_client/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def save_embedding(self, embedding):

def get_all_embeddings(self):
embeddings = self.db['embeddings']
return embeddings.find({})
return [e for e in embeddings.find({})]

0 comments on commit 0d88558

Please sign in to comment.