一、图片中的人脸检测
import cv2 as cv
image = cv.imread("D:/by2.png")
cv.imshow("input",image)
h,w = image.shape[:2]
detector = cv.CascadeClassifier(cv.data.haarcascades+"haarcascade_frontalface_alt.xml")
faces = detector.detectMultiScale(image,scaleFactor=1.10,minNeighbors=3,
minSize=(30,30),maxSize=(w//2,h//2))
for x,y,width,heigh in faces:
cv.rectangle(image,(x,y),(x+width,y+heigh),(0,0,255),2,cv.LINE_8,0)
cv.imshow("faces",image)
cv.waitKey(0)
cv.destroyAllWindows()
在上面的代码中,我们人脸检测使用的是cv2…CascadeClassifier()函数,它可以检测图片中所有的人脸。在该函数中,各参数和返回值的含义为:
①image:待检测图像&