Лицевые ориентиры с помощью dlib, OpenCV и Python - PullRequest
0 голосов
/ 09 декабря 2018

что я пытаюсь сделать, используя OpenCV, dlib и Python, это в основном идентифицировать лицевые ориентиры на наборе изображений, используя dlib из этого блога

Вот мой код:

from imutils import face_utils
import numpy as np
import argparse
import imutils
import dlib
import cv2

# initialize dlib's face detector (HOG-based) and then create
# the facial landmark predictor
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("C:\\Users\SONY\pycharmProjects\multiclass_face_recognition\shape_predictor_68_face_landmarks.dat")


# load the input image, resize it, and convert it to grayscale
image = cv2.imread("C:\\Users\SONY\PycharmProjects\multiclass_face_recognition\images\example_01.jpg")
print("the image readed")
image = imutils.resize(image, width=500)
print("the image resized")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
print("the image converted to gray")
print(gray)

# detect faces in the grayscale image
rects = detector(gray, 1)
print("the image detected")
# loop over the face detections
for (i, rect) in enumerate(rects):
    # array
    shape = predictor(gray, rect)
    shape = face_utils.shape_to_np(shape)


    (x, y, w, h) = face_utils.rect_to_bb(rect)
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)

    # show the face number
    cv2.putText(image, "Face #{}".format(i + 1), (x - 10, y - 10),
        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

    # loop over the (x, y)-coordinates for the facial landmarks
    # and draw them on the image
    for (x, y) in shape:
        cv2.circle(image, (x, y), 1, (0, 0, 255), -1)

# show the output image with the face detections + facial landmarks
cv2.imshow("Output", image)
cv2.waitKey(0)

Теперь я не получаю сообщение об ошибке, скрипт запускается, но он останавливается и дает сбой.Я знаю проблему при чтении изображения, потому что перед этим шагом оно напечатало сообщение, как только оно достигнет читаемого изображения, оно напечатает некоторую его часть и упало.Я уверен, что все пути правильные, и доказательства, которые он читает и распечатывает некоторую часть изображения и не могут вернуть ошибку объекта NonType, он выдает сообщение о проверке решения онлайн или остановке программы, а когда я проверял решение онлайн, он не может дать мне никакогорезультат.сообщение следующим образом:

enter image description here

Любые идеи и предложения помогут мне.Большое спасибо

...