HAAR和LBP数据
这是我使用的两个数据
链接:https://pan.baidu.com/s/1_JADYabXD1aUs_fHCH9YEQ
提取码:wj6g
复制这段内容后打开百度网盘手机App,操作更方便哦
from matplotlib import pyplot as plt
from cv2 import cv2 as cv
import numpy as np
#opencv基于HAAR实现人脸检测
def face_detect_HAAR(image):
#转换成灰度图像
gray =cv.cvtColor(image,cv.COLOR_BGR2GRAY)
#人脸识别器分类器
face_detetor = cv.CascadeClassifier('C:\\ruanjian\\model\\opencv-master\\data\\haarcascades\\haarcascade_frontalface_alt_tree.xml')
#在多个尺度空间对其进行人脸检测
faces = face_detetor.detectMultiScale(gray,1.02,3)
#faces = face_detetor.detectMultiScale(gray,scaleFactor=1.2,minNeighbors=3,minSize=(32,32))
for x,y,w,h in faces:
cv.rectangle(image,(x,y),(x+w,y+h),(0,0,255),2)#颜色,线宽
cv.imshow('face_detect_demo',image)
#opencv基于LBP实现人脸检测
def face_detect_LBP(image):
#转换成灰度图像
gray =cv.cvtColor(image,cv.COLOR_BGR2GRAY)
#人脸识别器分类器
face_detetor = cv.CascadeClassifier('C:\\ruanjian\\model\\opencv-master\\data\\lbpcascades\\lbpcascade_frontalcatface.xml')
#在多个尺度空间对其进行人脸检测
faces = face_detetor.detectMultiScale(gray,1.1,2)#后两个参数进行调整
#faces = face_detetor.detectMultiScale(gray,scaleFactor=1.2,minNeighbors=3,minSize=(32,32))
for x,y,w,h in faces:
cv.rectangle(image,(x,y),(x+w,y+h),(0,0,255),2)#颜色,线宽
cv.imshow('face_detect_demo',image)
if __name__ == "__main__":
filepath = "C:\\pictures\\7.jpg"
img = cv.imread(filepath) # blue green red
#试一下视频
capture = cv.VideoCapture(0)#自己的摄像头
while True:
ret,frame = capture.read()
frame = cv.flip(frame,1)#镜像
face_detect_HAAR(frame)
c = cv.waitKey(10)
if c == 27:#ESC
break
cv.namedWindow("input image",cv.WINDOW_AUTOSIZE)
cv.imshow("input image",img)
#face_detect_demo()
cv.waitKey(0)
cv.destroyAllWindows()