Face Recognition Project In Python With Source Code Free Download ^hot^ Review
Implement liveness detection to prevent the system from being fooled by a photograph. 📥 Source Code Free Download
import cv2 import face_recognition import os import numpy as np # Step 1: Load training images from the 'photos' folder path = 'photos' images = [] classNames = [] myList = os.listdir(path) for cl in myList: curImg = cv2.imread(f'{path}/{cl}') images.append(curImg) classNames.append(os.path.splitext(cl)[0]) print(f'Found {len(classNames)} identities: {classNames}') # Step 2: Function to find encodings for all training images def findEncodings(images): encodeList = [] for img in images: img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) encode = face_recognition.face_encodings(img)[0] encodeList.append(encode) return encodeList encodeListKnown = findEncodings(images) print('Encoding Complete. Starting Webcam...') # Step 3: Initialize Webcam cap = cv2.VideoCapture(0) while True: success, img = cap.read() # Resize image for faster processing imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25) imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB) # Find faces in the current frame facesCurFrame = face_recognition.face_locations(imgS) encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame) for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame): matches = face_recognition.compare_faces(encodeListKnown, encodeFace) faceDis = face_recognition.face_distance(encodeListKnown, encodeFace) # Find the best match matchIndex = np.argmin(faceDis) if matches[matchIndex]: name = classNames[matchIndex].upper() # Draw box and name y1, x2, y2, x1 = faceLoc y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4 cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2) cv2.rectangle(img, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED) cv2.putText(img, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2) cv2.imshow('Webcam Face Recognition', img) # Press 'q' to exit if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() Use code with caution. 🔍 How It Works Implement liveness detection to prevent the system from
Export the recognized names and timestamps to an Excel or CSV file. 🔍 How It Works Export the recognized names
The face_recognition library generates a 128-dimensional vector for each face. This vector is unique to the person's facial features. Before we dive into the code, you need
Before we dive into the code, you need to set up your Python environment. You will need Python 3.x installed on your machine. 1. Install Required Libraries