-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.py
More file actions
48 lines (40 loc) · 1.72 KB
/
Copy pathmonitor.py
File metadata and controls
48 lines (40 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from deepface import DeepFace
from core.bot import TelegramBot
from dotenv import load_dotenv
load_dotenv()
tel = TelegramBot(os.getenv("TOKEN"))
tel.run()
unknown_dir = './storage/unknown/'
for person_folder in os.listdir(unknown_dir):
person_path = os.path.join(unknown_dir, person_folder)
if os.path.isdir(person_path):
for frame_file in os.listdir(person_path):
if frame_file.endswith(('.jpg', '.png', '.jpeg')):
frame_path = os.path.join(person_path, frame_file)
faces = DeepFace.find(
frame_path,
db_path='./storage/faces',
detector_backend='retinaface',
enforce_detection=False,
model_name='Facenet512',
distance_metric='euclidean_l2',
threshold=0.9,
silent=True
)
if len(faces) > 0:
for face in faces:
if(face.empty):
print(face)
tel.bot.send_photo(
chat_id=5334875110,
photo=open(frame_path, 'rb'),
caption=f"Intrusion Detected At Door"
)
continue
name = face['identity'][0]
distance = face['distance'][0]
threshold = face['threshold'][0]
print(f"Frame {frame_file} matched with: {name} with distance: {distance} and threshold: {threshold}")
os.remove(frame_path)
os.rmdir(person_path)