# -*- coding: UTF-8 -*- import cv2 # 待检测的图片路径 imagepath="xhs.jpg" image = cv2.imread(imagepath) gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)#转换为灰度图,降低计算强度 face_cascade = cv2.CascadeClassifier('d:\haarcascades\haarcascade_frontalface_alt.xml') # 探测人脸 # 根据训练的数据来对新图片进行识别的过程。 faces = face_cascade.detectMultiScale( image,#必选参数,其他可以不写 scaleFactor= 1.01, #控制金字塔层数,通常范围1.01~1.5 参数越小,层数越多,结果越精确 minNeighbors = 1, #为5表示有5次重叠才认为人脸存在 minSize = (1,1),#寻找人脸的最小区域 ) # 处理人脸探测的结果 print ("{0}".format(len(faces))) for(x,y,w,h) in faces: cv2.rectangle(image,(x,y),(x+w,y+w),(0,255,0),2) cv2.imshow("image",image) cv2.waitKey(0)
cv2.destroyAllWindows()
参考:http://www.cnblogs.com/hanson1/p/7105265.html
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有