RuntimeError:无法打开C:\ Users \В\ PycharmProjects \ SiteOfRecognition \ SiteR \ MyApp \ shape_predictor_68_face_landmarks.dat

时间:2020-05-14 11:25:15

标签: python django dlib

问题

我正在制作一个网站,我需要识别人脸的各个部分。我用Django写。我想在MyApp views.py中使用cmd运行python文件,但遇到一个无法打开shape_predictor_68_face_landmarks.dat的错误。

这是完整的追溯

Traceback (most recent call last):
  File "C:\Users\В\PycharmProjects\SiteOfRecognition\SiteR\MyApp\static\MyApp\pythonHair\face_parts_detection.py", line 25, in <module>
    predictor = dlib.shape_predictor(args["shape_predictor"])
RuntimeError: Unable to open C:\Users\В\PycharmProjects\SiteOfRecognition\SiteR\MyApp\shape_predictor_68_face_landmarks.dat

This is my project pathes

这是我的观点的一部分。py

        else:


            import os
            os.system('cmd/k "python C:\\Users\\В\\PycharmProjects\\SiteOfRecognition\\SiteR\\MyApp\\static\\MyApp\\pythonHair\\face_parts_detection.py  --shape-predictor C:\\Users\\В\\PycharmProjects\\SiteOfRecognition\\SiteR\\MyApp\\shape_predictor_68_face_landmarks.dat --image images/face2.jpg "')

            return render(request, 'MyApp/DressPage.html')

这是face_parts_detection.py

from imutils import face_utils
import numpy as np
import argparse
import imutils
import dlib
import cv2
from matplotlib import pyplot as plt

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--shape-predictor", required=True,
    help="path to facial landmark predictor")

ap.add_argument("-i", "--image", required=True,
    help="path to input image")
args = vars(ap.parse_args())

# initialize dlib's face detector (HOG-based) and then create
# the facial landmark predictor
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(args["shape_predictor"])

# load the input image, resize it, and convert it to grayscale
image = cv2.imread(args["image"])
image = imutils.resize(image, width=500)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# detect faces in the grayscale image
rects = detector(gray, 1)
eyeBrows = 0

# loop over the face detections
for (i, rect) in enumerate(rects):
    # determine the facial landmarks for the face region, then
    # convert the landmark (x, y)-coordinates to a NumPy array
    shape = predictor(gray, rect)
    shape = face_utils.shape_to_np(shape)

    # loop over the face parts individually
    for (name, (i, j)) in face_utils.FACIAL_LANDMARKS_IDXS.items():
        # clone the original image so we can draw on it, then
        # display the name of the face part on the image
        clone = image.copy()
        cv2.putText(clone, name, (10, 30), cv2.FONT_HERSHEY_SIMPLEX,
            0.7, (0, 0, 255), 2)

        # loop over the subset of facial landmarks, drawing the
        # specific face part
        for (x, y) in shape[i:j]:
            cv2.circle(clone, (x, y), 1, (0, 0, 255), -1)

        # extract the ROI of the face region as a separate image
        (x, y, w, h) = cv2.boundingRect(np.array([shape[i:j]]))
        roi = image[y:y + h, x:x + w]
        roi = imutils.resize(roi, width=250, inter=cv2.INTER_CUBIC)

        # show the particular face part
        #cv2.imshow("ROI", roi)
        if eyeBrows == 3 :
            eyeBrows = eyeBrows + 1
            cv2.imwrite("results/1.jpg", roi)
        else:
            eyeBrows = eyeBrows + 1


        cv2.waitKey(0)

    # visualize all facial landmarks with a transparent overlay
    output = face_utils.visualize_facial_landmarks(image, shape)
    cv2.imshow("Output", output)
    cv2.waitKey(0)

我尝试了很多事情。我尝试了所有可能的路径,尝试将路径添加到face_parts_detection.py中, 试图更改shape_predictor_68_face_landmarks.dat的位置,但无济于事。

0 个答案:

没有答案