Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Face recognition #37

Open
Jen1331 opened this issue Dec 12, 2022 · 1 comment
Open

Face recognition #37

Jen1331 opened this issue Dec 12, 2022 · 1 comment

Comments

@Jen1331
Copy link

Jen1331 commented Dec 12, 2022

No description provided.

@Jen1331
Copy link
Author

Jen1331 commented Dec 12, 2022

Real Python

Python Face Recognition and Face Detection
Face Detection in Python Using a Webcam
by Shantnu Tiwari 174 Comments data-science machine-learning
Tweet Share Email
Table of Contents

Pre-requisites
The Code
Test!
Next Steps
Want to know more?
Remove ads
This tutorial is a follow-up to Face Recognition in Python, so make sure you’ve gone through that first post.

As mentioned in the first post, it’s quite easy to move from detecting faces in images to detecting them in video via a webcam - which is exactly what we will detail in this post.

Before you ask any questions in the comments section:

Do not skip over the blog post and try to run the code. You must understand what the code does not only to run it properly but to troubleshoot it as well.
Make sure to use OpenCV v2.
You need a working webcam for this script to work properly.
Review the other comments/questions as your questions have probably already been addressed.
Thank you.

Free Bonus: Click here to get the Python Face Detection & OpenCV Examples Mini-Guide that shows you practical code examples of real-world Python computer vision techniques.

Note: Also check out our updated tutorial on face detection using Python.

Pre-requisites
OpenCV installed (see the previous blog post for details)
A working webcam

Remove ads
The Code
Let’s dive straight into the code, taken from this repository.

import cv2
import sys

cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)

while True:
# Capture frame-by-frame
ret, frame = video_capture.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(30, 30),
    flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

# Display the resulting frame
cv2.imshow('Video', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
    break

When everything is done, release the capture

video_capture.release()
cv2.destroyAllWindows()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant