-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.txt
More file actions
155 lines (121 loc) · 5.62 KB
/
Copy pathREADME.txt
File metadata and controls
155 lines (121 loc) · 5.62 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Face Verification System
========================
Stack
-----
- Face detection + alignment : MTCNN (facenet-pytorch)
- Embedding model : InceptionResnetV1 / FaceNet (pretrained VGGFace2)
- Similarity : Cosine similarity (sklearn)
- Database : MongoDB
- UI : Streamlit
- Alerts : Gmail (smtplib, built into Python)
Project Structure
-----------------
face_verification_system/
│
├── app.py Streamlit UI — run this to start the app
├── register.py Registration logic (folder / webcam / bulk)
├── verify.py Verification logic (webcam + image upload)
│
├── embedding.py MTCNN + FaceNet — face detection & embedding
├── similarity.py Cosine similarity + top-1 matching
├── database.py MongoDB read/write (users, logs, unknowns)
├── alert.py Gmail email alerts with image attachment
│
├── config.py All settings — edit this first
│
├── data/
│ └── processed_data/ Dataset for bulk registration
│ ├── person_1/
│ │ ├── ID_1.jpg
│ │ ├── Selfie_1.jpg
│ │ └── Selfie_2.jpg
│ └── person_2/
│ └── ...
│
├── requirements.txt
└── README.txt
Setup
-----
1. Install dependencies
pip install -r requirements.txt
Note: First run downloads FaceNet weights (~90 MB) automatically.
2. Start MongoDB
Local : run "mongod" in a terminal
Cloud : use MongoDB Atlas free tier (https://www.mongodb.com/atlas)
paste connection URI into config.py → MONGO_URI
3. Configure config.py
Open config.py and fill in:
- MONGO_URI MongoDB connection string
- SENDER_EMAIL Gmail address used to send alerts
- SENDER_PASSWORD Gmail App Password (see below)
- ADMIN_EMAIL Where alert emails are delivered
4. Gmail App Password (one-time setup)
- Go to myaccount.google.com
- Security → enable 2-Step Verification
- Search "App Passwords" → generate one for Mail
- Copy the 16-character password into config.py
5. Test email alerts
python alert.py
You should receive a test email within seconds.
6. Register faces
Option A — via Streamlit UI (recommended):
streamlit run app.py → go to "Register Face" or "Bulk Register"
Option B — command line:
python register.py
7. Run the app
streamlit run app.py
How It Works
------------
Registration:
Images → MTCNN (detect + align) → FaceNet (512-dim embedding)
→ average all embeddings for a person → store in MongoDB
Verification (webcam or image upload):
Frame/image → MTCNN → FaceNet → cosine similarity vs all stored embeddings
→ if score >= threshold (default 0.75) → Verified
→ else → Unknown → save snapshot + send alert email
Alert triggers:
- Unknown face detected → email with snapshot attached
- N unknowns in X minutes → escalated alert email
- Same person within time window → duplicate entry alert
- System error → error alert
Configuration Reference (config.py)
------------------------------------
SIMILARITY_THRESHOLD default 0.75 min cosine score to accept a match
DUPLICATE_WINDOW_SEC default 60 seconds before same person can re-log
UNKNOWN_ALERT_COUNT default 3 unknowns before escalated alert fires
UNKNOWN_ALERT_WINDOW default 5 minutes for the escalation window
DEVICE default "cpu" change to "cuda" if GPU available
Notes
-----
- Do NOT push config.py to GitHub if it contains real credentials.
Add it to .gitignore or replace credentials with placeholders before pushing.
- embeddings are stored as lists in MongoDB (auto-converted to np.array on load).
- Bulk registration skips already-registered persons by default.
Optimizing tool selection...
Read [](file:///d%3A/sem6/CV_project/face_verification_system/app.py#1-1), lines 1 to 50
Read [](file:///d%3A/sem6/CV_project/face_verification_system/requirements.txt)
Read [](file:///d%3A/sem6/CV_project/face_verification_system/README.txt#1-1), lines 1 to 100
Read [](file:///d%3A/sem6/CV_project/face_verification_system/config.py)
## **Face Verification System** — Brief Overview
**Purpose:**
A real-time face recognition system that registers users' faces and verifies them against a database. Unknown faces trigger email alerts to an admin.
**Core Technologies:**
- **Face Detection & Alignment**: MTCNN (via facenet-pytorch)
- **Face Embedding Model**: InceptionResNetV1 / FaceNet (pretrained on VGGFace2)
- **Similarity Matching**: Cosine similarity (scikit-learn)
- **Database**: MongoDB (stores users, logs, unknowns)
- **UI Framework**: Streamlit (web interface)
- **Alerts**: Gmail (smtplib) for email notifications
- **Languages**: Python with PyTorch, OpenCV
**Workflow:**
1. **Registration** → Images → MTCNN detects & aligns faces → FaceNet generates 512-dimensional embeddings → averaged per user → stored in MongoDB
2. **Verification** → Webcam/image upload → MTCNN + FaceNet embedding → compared against stored embeddings using cosine similarity
3. **Alerts** → Unknown faces (score < 0.75) trigger email notifications with snapshots; escalation if multiple unknowns detected
**Key Features:**
- Bulk registration from dataset folders
- Webcam-based registration/verification
- Real-time video stream verification
- Configurable similarity threshold (default 0.75)
- MongoDB-backed user management
- Automated email alerts with attachments
- Duplicate entry detection within configurable time windows