# -*-coding:utf-8-*-
#author: lyp time: 2018/8/10
import cv2
import numpy as np
face_xml = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_xml = cv2.CascadeClassifier('haarcascade_eye.xml')
img = cv2.imread('lyp.jpg')
cv2.imshow('src', img)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_xml.detectMultiScale(gray, 1.3, 5)
print('face=', len(faces))
for (x, y, w, h) in faces:
cv2.rectangle(img, (x,y), (x+w, y+h), (255, 0, 0), 2)
roi_face = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
eyes = eye_xml.detectMultiScale(roi_face)
print('eye=',len(eyes))
for (e_x,e_y,e_w,e_h) in eyes:
cv2.rectangle(roi_color, (e_x, e_y),(e_x+e_w, e_y+e_h),(0,255,0),2)
cv2.imshow('dst', img)
cv2.waitKey(0)文章来源地址https://www.toymoban.com/news/detail-498237.html
文章来源:https://www.toymoban.com/news/detail-498237.html
到了这里,关于【人脸检测1】Haar+Adaboost Demo的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!