opencv Haar特征+adaboost人脸识别

import cv2
import numpy as np
face_xml = cv2.CascadeClassifier("E:/code/conputer_visual/data/face_recognition/haarcascade_frontalface_default.xml")
eyes_xml = cv2.CascadeClassifier("E:/code/conputer_visual/data/face_recognition/haarcascade_eye.xml")
img = cv2.imread("E:/code/conputer_visual/data/face_recognition/1.png")
cv2.imshow("src", img)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#1灰度图数据 2缩放系数 3目标大小(face不小于5个像素)
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 = eyes_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.imwrite("E:/code/conputer_visual/data/face_recognition/face_me1.jpg", img)
cv2.waitKey(0)

opencv Haar特征+adaboost人脸识别_第1张图片
opencv Haar特征+adaboost人脸识别_第2张图片

你可能感兴趣的:(opencv,人脸识别,opencv,cv,计算机视觉)