0% found this document useful (0 votes)
5 views3 pages

python face lock code for multiple ojects

The document describes a Multiple User Face Recognition system that allows shared access to devices by recognizing several authorized users. It outlines the process of encoding faces, comparing them against a webcam feed, and granting access upon recognition. Additionally, it includes setup instructions, example Python code, and potential add-ons for enhanced functionality.

Uploaded by

aryanforjs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

python face lock code for multiple ojects

The document describes a Multiple User Face Recognition system that allows shared access to devices by recognizing several authorized users. It outlines the process of encoding faces, comparing them against a webcam feed, and granting access upon recognition. Additionally, it includes setup instructions, example Python code, and potential add-ons for enhanced functionality.

Uploaded by

aryanforjs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Great!

✅ **Multiple User Face Recognition** allows your face lock to recognize


several authorized users. This is useful for shared devices or access control
systems.

---

### 🔧 How It Works

1. Load and encode multiple authorized faces.


2. Compare webcam faces against the list of authorized encodings.
3. If a match is found, show which person was recognized and grant access.

---

### 📁 Folder Structure Example

```
face_lock_project/
├── known_faces/
│ ├── user1.jpg
│ ├── user2.jpg
│ └── user3.jpg
└── face_lock.py
```

---

### 💻 Python Code for Multiple User Face Lock

```python
import face_recognition
import cv2
import os
import numpy as np

# Load all known faces


known_face_encodings = []
known_face_names = []

known_faces_dir = "known_faces"

# Loop over all files in the known_faces directory


for filename in os.listdir(known_faces_dir):
if filename.endswith(".jpg") or filename.endswith(".png"):
path = os.path.join(known_faces_dir, filename)
image = face_recognition.load_image_file(path)
encodings = face_recognition.face_encodings(image)
if encodings:
known_face_encodings.append(encodings[0])
name = os.path.splitext(filename)[0] # Remove file extension
known_face_names.append(name)
else:
print(f"❌ No face found in {filename}")

# Start webcam
cap = cv2.VideoCapture(0)
print("🔍 Scanning for known faces... (Press 'q' to exit)")

while True:
ret, frame = cap.read()
if not ret:
break

# Resize frame for speed


small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
rgb_small_frame = small_frame[:, :, ::-1] # BGR to RGB

# Find all faces and encodings


face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(rgb_small_frame,
face_locations)

# Match each face found


for face_encoding, face_location in zip(face_encodings, face_locations):
matches = face_recognition.compare_faces(known_face_encodings,
face_encoding)
face_distances = face_recognition.face_distance(known_face_encodings,
face_encoding)

name = "Unknown"

if matches:
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]

# Draw box and label


top, right, bottom, left = [v * 4 for v in face_location] # Scale back up
cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0) if name !=
"Unknown" else (0, 0, 255), 2)
cv2.putText(frame, name, (left, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9,
(255, 255, 255), 2)

cv2.imshow("Face Lock - Multiple User", frame)

if cv2.waitKey(1) & 0xFF == ord('q'):


break

cap.release()
cv2.destroyAllWindows()
```

---

### ✅ Setup Instructions

1. Place one clear face photo of each user in the `known_faces/` folder.
2. The filename (e.g., `sir.jpg`) will be the name shown when recognized.
3. Run the script, and it will show “Unknown” for anyone not in the list.

---

### 🚀 Possible Add-Ons

* Face **registration system** (automatically add new users via GUI).


* Lock/unlock folder, browser, or computer session based on face.
* **Voice + Face authentication** combo.
* Save logs of who accessed and when.
Want help with any of these advanced features or GUI for easier use?

You might also like