人脸检测

这里主要是代码层面的

import cv2 as cv
import numpy as np


def face_detect_demo(image):
    gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
    # 检测器
    face_detector = cv.CascadeClassifier(r"haarcascade_frontalface_default.xml")
    # 多个尺度空间进行人脸检测
    faces = face_detector.detectMultiScale(gray, 1.1, 2)
    for x, y, w, h in faces:
        cv.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
    cv.imshow("result", image)


# 这里是视频操作的代码,不方便展示就加注释了
# capture = cv.VideoCapture('D:\movie.mkv')
# cv.namedWindow("result", cv.WINDOW_AUTOSIZE)
# while True:
# ret, frame = capture.read()
# frame = cv.flip(frame, 1)
# face_detect_demo(frame)
# c = cv.waitKey(10)
# if c == 27: # ESC
# break
src = cv.imread('people.png')
face_detect_demo(src)
cv.waitKey(0)

cv.destroyAllWindows()


主要是分类器的下载,下载地址为:
你点我啊