import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread("23.png")
#获取XML文件,加载人脸检测器
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#调用函数detecMultiScale
faces = faceCascade.detectMultiScale(gray,scaleFactor = 1.15, minNeighbors = 5,minSize = (5,5))
print(faces)
#打印输出的测试结果
print("发现{0}个人脸!".format(len(faces)))
#逐个标注人脸
for(x,y,w,h) in faces:
#cv2.rectangle(img,(x,y),(x+w),(y+w),(0,2255,0),2) #矩形标记
cv2.circle(img,(int((x+x+w)/2),int((y+y+h)/2)),int(w/2),(0,255,0),2)
#显示结果
cv2.imshow("dect",img)
cv2.waitKey()
cv2.destroyAllWindows()
haar级联分类器检测人脸位置
最新推荐文章于 2024-01-20 10:31:12 发布