十行代码轻松搞定人脸检测

首先导包:

import numpy as np
import cv2
import matplotlib.pyplot as plt
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

开始书写人脸检测的代码:

image=imread('123.jpg')#读入图片
#
级联分类器 detector = cv2.CascadeClassifier('haarcascade_frontalface_alt.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) show(image)

搞定!!!显示结果如下:

 

posted @ 2019-07-04 20:09  Geeksongs  阅读(392)  评论(0编辑  收藏  举报

Coded by Geeksongs on Linux

All rights reserved, no one is allowed to pirate or use the document for other purposes.