Spaces:
Sleeping
Sleeping
| import cv2 | |
| import numpy as np | |
| def recognize_face(image): | |
| try: | |
| # Convert image to grayscale | |
| gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
| # Load OpenCV's pre-trained Haar Cascade for face detection | |
| face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') | |
| if face_cascade.empty(): | |
| raise Exception("Failed to load Haar Cascade classifier") | |
| # Detect faces in the image | |
| faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5) | |
| if len(faces) > 0: | |
| return "Customer" # Face detected, assume it's a customer | |
| else: | |
| return "Unknown" # No face detected | |
| except Exception as e: | |
| print(f"Error in face recognition: {e}") | |
| return "Error reading face" |