Artificial intelligence-OpenCV+Python realizes face recognition (video face detection)

In the previous article, we shared how opencv recognizes faces in pictures, and how to detect faces in OpenCV pictures . In this issue, we share how to detect faces from videos.


Video face detection
OpenCV is very simple to open the camera, just need the following line of code
capture = cv2.VideoCapture(0) # Open the camera
After opening the camera, we use the following line of code to get the picture in the video (picture of each frame)
ret, frame = capture.read() # Read
With the picture, we can detect the face according to the picture recognition method With
the above 2 codes, plus the picture recognition in the previous issue, we can detect the face from the video
Full code:

import cv2
capture = cv2.VideoCapture(0) # 打开摄像头
face = cv2.CascadeClassifier(r'D:\Program Files (x86)\Anaconda3\pkgs\
libopencv-3.4.1-h875b8b8_3\Library\etc\haarcascades\
haarcascade_frontalface_alt.xml') # 导入人脸模型
cv2.namedWin

Guess you like

Origin blog.csdn.net/weixin_44782294/article/details/131711743