diff --git a/.gitignore b/.gitignore index 47d1dc5..df2412e 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/50ms b/50ms new file mode 100644 index 0000000..e69de29 diff --git a/src/biometric/face_detection.py b/src/biometric/face_detection.py index cdbe31f..0081b57 100644 --- a/src/biometric/face_detection.py +++ b/src/biometric/face_detection.py @@ -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__) @@ -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() \ No newline at end of file diff --git a/test_camera.py b/test_camera.py new file mode 100644 index 0000000..d075082 --- /dev/null +++ b/test_camera.py @@ -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() \ No newline at end of file diff --git a/test_face_detection.py b/test_face_detection.py new file mode 100644 index 0000000..21e901d --- /dev/null +++ b/test_face_detection.py @@ -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() \ No newline at end of file