opencv实现人脸识别

版权声明:本文为pureszgd原创文章,未经允许不得转载, 要转载请评论留言! https://blog.csdn.net/pureszgd/article/details/83243496
import cv2
import matplotlib.pylab as plt
import numpy as np

def show(image):
    plt.imshow(image)
    plt.axis('off')
    plt.show()

def imread(image):
    image = cv2.imread(image)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    return image
def face_detect(image):
    image = imread(image)
    detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
    rects = detector.detectMultiScale(image, scaleFactor=1.1, minNeighbors=2, minSize=(10, 10),
                                      flags=cv2.CASCADE_SCALE_IMAGE)

    for (x, y, w, h) in rects:
        # draw rect
        cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)

    show(image)

face_detect('face.jpg')

xml下载地址:

https://github.com/opencv/opencv/tree/master/data/haarcascades

猜你喜欢

转载自blog.csdn.net/pureszgd/article/details/83243496