I have a face detection program that can draw a rectangle around a face when it sees it. However, I want my program to be able to recognize certain faces and be able to display the face's name.
Here's my current code:
import cv2
#load the cascade
face_cascade =
cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
#capture video from webcam
cap = cv2.VideoCapture(0)
#continuously capture video
while True:
#read the frame
_, img = cap.read()
#convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#detect a face
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
#draw a rectangle to confirm face
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
#display video
cv2.imshow('img', img)
#stop if escape key is pressed
k = cv2.waitKey(30) & 0xff
if k == 27:
break
#release the video capture object
cap.release()
How can I implement face recognition while still using the code I have and without making any drastic changes? Any help will be gladly appreciated.
Nevermind, I figured it out. I decided to use the face_recognition
library with help from this page: enter link description here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.