我试图检测人脸的 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 级联人脸检测器对我的面部图像没有好处。谁能帮帮我吗。