使用opencv dnn人脸检测器检测检测到的人脸图像内的人脸界标 [英] Detect facial landmarks inside a detected face image using opencv dnn face detector

查看:93
本文介绍了使用opencv dnn人脸检测器检测检测到的人脸图像内的人脸界标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测人脸的68个面部标志.我在

I trying to detect the 68 facial landmarks of human face. I detected the face using OpenCV dnn face detector as in https://www.pyimagesearch.com/2018/02/26/face-detection-with-opencv-and-deep-learning/ The face detection process done successfully, this is my code:

# import the necessary packages
import numpy as np
import argparse
import cv2
import dlib

ap = argparse.ArgumentParser()
ap.add_argument("-c", "--confidence", type=float, default=0.5,
                help="minimum probability to filter weak detections")
args = vars(ap.parse_args())

# load our serialized model from disk
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe("D:\deep-learning-face-detection\deploy.prototxt.txt",
                               r"D:\deep-learning-face-detection\res10_300x300_ssd_iter_140000.caffemodel")

image = cv2.imread("image\path\jpg")
(h, w) = image.shape[:2]
blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)), 1.0,
                             (300, 300), (104.0, 177.0, 123.0))

print("[INFO] computing object detections...")
net.setInput(blob)
detections = net.forward()

# loop over the detections
for i in range(0, detections.shape[2]):
    # extract the confidence (i.e., probability) associated with the
    # prediction
    confidence = detections[0, 0, i, 2]

    # filter out weak detections by ensuring the `confidence` is
    # greater than the minimum confidence
    if confidence > args["confidence"]:
        # compute the (x, y)-coordinates of the bounding box for the
        # object
        box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
        (startX, startY, endX, endY) = box.astype("int")

        # draw the bounding box of the face along with the associated
        # probability
        text = "Face#{}".format(i)
        y = startY - 10 if startY - 10 > 10 else startY + 10
        cv2.rectangle(image, (startX, startY), (endX, endY),
                      (0, 0, 255), 2)
        cv2.putText(image, text, (startX, y),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)

    # show the output image
cv2.imshow("Output", image)
cv2.waitKey(0)

但是当我尝试检测面部内部的面部标志时,如下所示:

but when I trying to detect the facial landmarks inside the face, as the following:

predictor = dlib.shape_predictor("D:\shape_predictor_68_face_landmarks.dat")
shape = predictor(image, detections)
vec = []
for i in range(68):
    v = shape.part(i)
    vec.append(v)
print(vec)

我收到以下错误消息

形状=预测变量(图像,检测物)TypeError:调用():不兼容的函数参数.以下参数类型是支持的:1.(自:dlib.shape_predictor,图像:数组,框:dlib.rectangle)-> dlib.full_object_detection

shape = predictor(image, detections) TypeError: call(): incompatible function arguments. The following argument types are supported: 1. (self: dlib.shape_predictor, image: array, box: dlib.rectangle) -> dlib.full_object_detection

调用了:,数组([[[0,0,0],[0,0,0],[0,0,0],...,

Invoked with: , array([[[ 0, 0, 0], [ 0, 0, 0], [ 0, 0, 0], ...,

当我使用OpenCV dnn面部检测器和MTCNN来回dlib面部检测器时出现错误消息,但是在Haar级联面部检测器中无法显示该错误消息,并且成功检测到面部标志.我想在上述OpenCV dnn人脸检测器中检测到人脸标志,因为它的准确性很高,因为高遮挡一致性,Haar级联人脸检测器无法从我的人脸图像中受益.谁能帮我.

The error message appeared when I'm using OpenCV dnn face detector, and MTCNN fro dlib face detector, but it cannot be appeared with Haar cascade face detector and the facial landmarks detected successfully. I want to detect the facial landmarks within the OpenCV dnn face detector as the above code due to its accurate where the Haar cascade face detector don't benefit with my face image due to high occlusions consistence. Can anyone please help me.

推荐答案

这将解决问题:

shape = predictor(image,dlib.rectangle(startX, startY, endX, endY))

这篇关于使用opencv dnn人脸检测器检测检测到的人脸图像内的人脸界标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆