0

我试图检测人脸的 68 个面部特征。我使用 OpenCV dnn 人脸检测器检测到人脸,如https://www.pyimagesearch.com/2018/02/26/face-detection-with-opencv-and-deep-learning/ 人脸检测过程成功完成,这是我的代码:

# 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)

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

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)

我收到以下错误消息

shape = predictor(image, detections) TypeError: call (): 不兼容的函数参数。支持以下参数类型: 1. (self: dlib.shape_predictor, image: array, box: dlib.rectangle) -> dlib.full_object_detection

调用: , array([[[ 0, 0, 0], [ 0, 0, 0], [ 0, 0, 0], ...,

当我使用 OpenCV dnn 人脸检测器和 MTCNN fro dlib 人脸检测器时出现错误消息,但使用 Haar 级联人脸检测器无法出现错误消息,并且成功检测到面部标志。我想将 OpenCV dnn 人脸检测器中的面部地标检测为上述代码,因为它的准确性很高,因为高遮挡一致性,Haar 级联人脸检测器对我的面部图像没有好处。谁能帮帮我吗。

4

3 回答 3

2

这将解决问题:

shape = predictor(image,dlib.rectangle(startX, startY, endX, endY))
于 2020-09-02T10:31:10.600 回答
0

作为参考shape_predictor,输入应该是图像和单个框。看来你放的不止一个。

你可以试试:

  1. 检查检测大小是否 > 0 => 如果为真,则转到步骤 2,否则未检测到人脸。
  2. 尝试

形状 = 预测器(图像,检测 [0])

=> 获取第一张脸的地标

于 2019-07-24T08:41:59.380 回答
0

如果你想要这样的东西: 示例 你可以使用人脸识别中的 face_recognition.face_landmarks(image) 函数,它比 dnn 检测器更容易使用。我希望我有所帮助。

于 2019-07-23T13:03:55.180 回答