【python 人脸检测】opencv 进行人脸检测

这里写图片描述

这里写图片描述

#coding=utf-8
import time
time1=time.time()
import cv2
#初始化 opencv 的 Cascade Classification,它的作用是产生一个检测器
faceCascade = cv2.CascadeClassifier("E:/haarcascade_frontalface_default.xml")
image = cv2.imread("E:/888.jpg")
#图像灰度化
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#调用
faces = faceCascade.detectMultiScale(gray,scaleFactor=1.15,minNeighbors=5,minSize=(5,5))
print "Found {0} faces!".format(len(faces))
#######显示图像并丏标记用斱框标出来
for (x, y, w, h) in faces:
    cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
    cv2.imshow("Faces found", image)



cv2.waitKey(0)
cv2.destroyAllWindows()


time2=time.time()
print u'ok,程序结束!'
print u'总共耗时:'+str(time2-time1)+'s'

这里写图片描述

"D:\Program Files\Python27\python.exe" D:/PycharmProjects/learn2017/行人检测.py
Found 6 faces!
ok,程序结束!
总共耗时:6.36999988556s

Process finished with exit code 0

再来一张大牛合照
这里写图片描述

"D:\Program Files\Python27\python.exe" D:/PycharmProjects/learn2017/行人检测.py
Found 4 faces!
ok,程序结束!
总共耗时:17.0020000935s

Process finished with exit code 0
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页