python opencv识别人脸人眼

import cv2
import numpy as np
import matplotlib.pyplot as plt

face_cascade =cv2.CascadeClassifier(r"D:\anaconda\Lib\site-packages\cv2\data\haarcascade_frontalface_default.xml")
eye_cascade =cv2.CascadeClassifier(r"D:\anaconda\Lib\site-packages\cv2\data\haarcascade_eye.xml")

img=plt.imread(r"D:\test_photo0.jpg")
img=np.array(img)
faces = face_cascade.detectMultiScale(img, 1.3, 5)
plt.rcParams['figure.figsize'] = (30.0,30.0) 
plt.subplot(1,5,1)
plt.imshow(img)

for i,(x,y,w,h) in enumerate(faces):
    plt.subplot(1,5,i+2)
    face=img[y:y+h,x:x+w]
    plt.imshow(face)
    
    eyes=eye_cascade.detectMultiScale(face)    
    for (x_eye,y_eye,w_eye,h_eye) in eyes:
        plt.plot([x_eye,x_eye,x_eye+w_eye,x_eye+w_eye,x_eye],[y_eye,y_eye+h_eye,y_eye+h_eye,y_eye,y_eye])

plt.show()

python opencv识别人脸人眼_第1张图片 

python opencv识别人脸人眼_第2张图片

python opencv识别人脸人眼_第3张图片 

 

你可能感兴趣的:(机器学习,神经网络)