作者:手机用户2602909207 | 来源:互联网 | 2023-09-06 07:13
1.示例代码importcv2if__name____main__:imgcv2.imread(r..\img\burenshi.jpg)#加载人脸检测模型face_detect
1.示例代码
import cv2if __name__ == '__main__':img = cv2.imread(r'..\img\burenshi.jpg')#加载人脸检测模型face_detector = cv2.CascadeClassifier(r'c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\cv2\data\haarcascade_frontalface_alt2.xml')#调参增加检测精度faces = face_detector.detectMultiScale(img,scaleFactor=1.1, #缩放每次检测范围,默认1.1minNeighbors=3)#绘制人脸检测ROIfor x,y,w,h in faces: cv2.rectangle(img,pt1=(x,y),pt2=(x+w,y+h),color=[0,0,255],thickness=2) cv2.imshow('face', img)cv2.waitKey(0)cv2.destroyAllWindows()
2.结果展示
总结
基于openCV的人脸检测,首先要引入人脸检测模型,然后在使用其绘图函数绘制脸部ROI区域。