Introduction to Face RecognitionFace recognition differs from face detection. Detection simply finds a face in an image, while recognition identifies who that person is. OpenCV provides built-in recognizers like LBPH (Local Binary Patterns Histograms) which are efficient for real-time applications on standard hardware.
cam = cv2.VideoCapture(0)while True:ret, img = cam.read()gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)faces = faceCascade.detectMultiScale(gray, 1.2, 5) face recognition opencv source code download
This lightweight approach is perfect for attendance systems, security gates, or personalized smart mirrors. For higher accuracy, you can later explore Deep Learning methods like FaceNet or dlib. To help you refine this project: cam = cv2
Data Gathering: Capturing images of the person you want to recognize. PrerequisitesTo run the source code, you need Python
PrerequisitesTo run the source code, you need Python installed on your system. You will also need to install the OpenCV library and the contrib module which contains the recognition algorithms.
while(True):ret, img = cam.read()gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)faces = face_detector.detectMultiScale(gray, 1.3, 5)
Source Code: Part 1 - Face Dataset GeneratorThis script captures 30 samples from your webcam and saves them to a folder named 'dataset'. import cv2import os