mtcnn+opencv实现人脸检测

import matplotlib.pyplot as plt
import tensorflow.keras
from mtcnn.mtcnn import MTCNN
from matplotlib.patches import Rectangle
import cv2 as cv2

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)

img = plt.imread('xz.jpg')

model = MTCNN()

faces = model.detect_faces(img)

for face in faces:
    print(face)

def draw_boxes(img_path,faces):
    img = plt.imread(img_path)

    plt.imshow(img)

    ax = plt.gca()

    for face in faces:
        x,y,w,h = face['box']
        rect = Rectangle((x,y),w,y,fill=False,color='blue')
        ax.add_patch(rect)

        for k,v in face['Keypoints'].item():
            point = Circle(v,redius=2,color='red')
            ax.add_patch(point)

    plt.show()

你可能感兴趣的:(opencv,python,tensorflow)