python+opencv提取图片中的人脸

当前环境

系统: windows 10 64

python版本:3.7.3

opencv 版本:3.4.4

python官网:https://www.python.org/

opencv下载地址:https://pypi.tuna.tsinghua.edu.cn/simple/opencv-python/

当前例子为:展示出截取的头像,显示图像并将人像画框

def facedetect(image):
    image = imread(image)
    # 级联分类器
    detector = cv2.CascadeClassifier("D:/study/tf/03/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:
        # 画矩形框
        #cv2.rectangle(image, (x,y), (x+w,y+h), (0,255,0),2)
        cv2.rectangle(image, (x,y), (x+w,y+h), (0,0,0),0)
        tl = image[y:y+w,x:x+h]
        plt.imshow(tl)
        plt.axis('off')
        plt.show()

    show(image)

 

你可能感兴趣的:(python,人脸识别,opencv)