Edit Content

Est adipisci rutrum minim hat dolorum, nobis nonummy natoque dolores delectus magna turpis.

Face Detection Using OpenCV (Real-Time)

ABC AI & Robotics Research Institute Blog 5

Overview: Detect human faces in live webcam feed.

Use Case: Surveillance systems, automated greeting kiosks, access control.

Library: opencv-python

Installation:

pip install opencv-python

Working Code:

import cv2
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
    cv2.imshow('Face Detection', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Editor Tip: Use VS Code with OpenCV IntelliSense enabled.

About the Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these