Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 3 additions & 57 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,58 +1,4 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual environments
templates/
.venv/
venv/
ENV/
env/
.env

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Logs
*.log
logs/

# Temporary files
tmp/
temp/
tmp_templates/

# Model files (if large)
models/*.pkl
models/*.h5
models/*.model

# Configuration files with sensitive data
config/local.yaml
config/production.yaml
__pycache__/
*.pyc
Empty file added 50ms
Empty file.
45 changes: 30 additions & 15 deletions src/biometric/face_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
except Exception: # pragma: no cover - runtime dependency guard
ort = None # type: ignore[assignment]

from core.logging import get_logger, PerformanceTimer
from core.exceptions import FaceDetectionError, ModelLoadError
from src.core.logging import get_logger, PerformanceTimer
from src.core.exceptions import FaceDetectionError, ModelLoadError

logger = get_logger(__name__)

Expand Down Expand Up @@ -416,22 +416,37 @@ def _resolve_haarcascade_path(self) -> str:
return "haarcascade_frontalface_default.xml"


# Example usage and testing
if __name__ == "__main__":
# Test face detection
detector = FaceDetector(backend="opencv") # Use OpenCV for testing
detector = FaceDetector(backend="opencv")

print("Testing face detection...")
cap = cv2.VideoCapture(0)

# Create a test image (in practice, this would come from camera)
test_image = np.zeros((480, 640, 3), dtype=np.uint8)
if not cap.isOpened():
print("Error: Cannot access camera")
exit()

# Test detection
faces = detector.detect_faces(test_image)
print(f"Detected {len(faces)} faces")
print("Press 'q' to exit")

if faces:
largest_face = detector.detect_largest_face(test_image)
print(f"Largest face: {largest_face}")
while True:
ret, frame = cap.read()
if not ret:
break

print("Face detection test completed!")
# Detect faces
faces = detector.detect_faces(frame)

print("Faces detected:", len(faces))

# Draw boxes
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

# SHOW WINDOW 🔥
cv2.imshow("Face Detection", frame)

# Exit on 'q'
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()
39 changes: 39 additions & 0 deletions test_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from src.biometric.face_detection import FaceDetector
import cv2

detector = FaceDetector(backend="opencv")

cap = cv2.VideoCapture(0)

if not cap.isOpened():
print("❌ Cannot access camera")
exit()

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

# Resize frame for faster processing
small_frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5)

# Detect faces on smaller frame
faces = detector.detect_faces(small_frame)

# Scale faces back to original size
scaled_faces = []
for (x, y, w, h) in faces:
scaled_faces.append((x * 2, y * 2, w * 2, h * 2))

# Draw on original frame
frame = detector.visualize_detections(frame, scaled_faces)

# SHOW WINDOW (correct indentation)
cv2.imshow("Face Detection", frame)

# Press ESC to exit
if cv2.waitKey(1) & 0xFF == 27:
break

cap.release()
cv2.destroyAllWindows()
28 changes: 28 additions & 0 deletions test_face_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import cv2
import sys, os
sys.path.append(os.path.abspath("LockLess/src"))

from src.biometric.face_detection import FaceDetector
detector = FaceDetector(backend="opencv")

cap = cv2.VideoCapture(0)

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

faces = detector.detect_faces(frame)

print("Faces detected:", len(faces)) # 👈 IMPORTANT

for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

cv2.imshow("Face Detection", frame)

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

cap.release()
cv2.destroyAllWindows()