在预测器中有错误 = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") RuntimeError: [英] Having error in predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") RuntimeError:
问题描述
我一直在第 8 行出错.
I'm keep running with error in line 8.
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") 运行时错误:无法打开 shape_predictor_68_face_landmarks.da
我下载了我尝试将文件添加到工作目录的文件,但 PyCharm 不允许我拖放任何内容.
I downloaded the files I tried to add the files to working directory but PyCharm doesn't let me drag and drop anything.
import cv2
import numpy as np
import dlib
cap = cv2.VideoCapture(0)
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
def midpoint(p1 ,p2):
return int((p1.x + p2.x)/2), int((p1.y + p2.y)/2)
while True:
_, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detector(gray)
for face in faces:
#x, y = face.left(), face.top()
#x1, y1 = face.right(), face.bottom()
#cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2)
landmarks = predictor(gray, face)
left_point = (landmarks.part(36).x, landmarks.part(36).y)
right_point = (landmarks.part(39).x, landmarks.part(39).y)
center_top = midpoint(landmarks.part(37), landmarks.part(38))
center_bottom = midpoint(landmarks.part(41), landmarks.part(40))
hor_line = cv2.line(frame, left_point, right_point, (0, 255, 0), 2)
ver_line = cv2.line(frame, center_top, center_bottom, (0, 255, 0), 2)
cv2.imshow("Frame", frame)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
推荐答案
解决问题.我进入了我的 Mac open pycharm install dlib ,起初我遇到了同样的问题.谷歌 shape_predictor_68_face_landmarks.dat 中的类型.搜索不同选项的最佳来源:https://github.com/davisking/dlib-models/blob/master/shape_predictor_68_face_landmarks.dat.bz2 下载文件,我把文件放到 sam 中
Solve the problem. I went in my Mac open pycharm install dlib and at first I had the same problem. the type in google shape_predictor_68_face_landmarks.dat. search different option the best source: https://github.com/davisking/dlib-models/blob/master/shape_predictor_68_face_landmarks.dat.bz2 download the file and I dropped the file in sam
这篇关于在预测器中有错误 = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") RuntimeError:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!