dlib模块中的shape_predictor使用相对路径时的ArgumentError

时间:2016-12-03 15:25:31

标签: python python-2.7 dlib python-os

使用dlib.shape_predictor函数时遇到一个奇怪的错误。

这是我的代码:

import sys
import dlib
from skimage import io
import matplotlib.pyplot as plt
import os


predictor_model = os.path.join(os.path.dirname(__file__),"Models","shape_predictor_68_face_landmarks.dat")

# Take the image file name from the command line
file_name = "/home/matt/Programming/Python/Face_detection/Images/wedding_photo.jpg"

# Test if they are equivalent
print predictor_model == "/home/matt/Programming/Python/Face_detection/Models/shape_predictor_68_face_landmarks.dat"

predictor_model = "/home/matt/Programming/Python/Face_detection/Models/shape_predictor_68_face_landmarks.dat"

# Create a HOG face detector using the built-in dlib class
face_detector = dlib.get_frontal_face_detector()
face_pose_predictor = dlib.shape_predictor(predictor_model)

如果我使用os通过相对路径定义的预测变量模型,那么我会收到错误:

ArgumentError: Python argument types in
    shape_predictor.__init__(shape_predictor, unicode)
did not match C++ signature:
    __init__(boost::python::api::object, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
    __init__(_object*)

如果我按照上面的定义对路径进行硬编码,则脚本运行时没有问题。什么想法可能出错?

0 个答案:

没有答案