HAAR与LBP特征数据下载:https://download.csdn.net/download/zhouzongzong/11265103
实例:
import cv2
import numpy as np
def face_detecte(img):
print(img.shape)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
face_detector = cv2.CascadeClassifier("C:\\Users\\Desktop\\opencv-master\\data\\haarcascades\\haarcascade_frontalface_alt_tree.xml")
eye_detector = cv2.CascadeClassifier("C:\\Users\\Desktop\\opencv-master\\data\\haarcascades\\haarcascade_eye_tree_eyeglasses.xml")
faces = face_detector.detectMultiScale(gray,1.02,2)
for x,y,w,h in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
eyes = eye_detector.detectMultiScale(gray)
for x,y,w,h in eyes:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
cv2.imshow("return",img)
img = cv2.imread('11.jpg',1)
cv2.namedWindow('return', 0)
cv2.resizeWindow('img', 480, 320)
cv2.resizeWindow('return',480, 320)
cv2.imshow('img', img)
face_detecte(img)
cv2.waitKey(0)
cv2.destroyAllWindows()