我按照http://npatta01.github.io/2015/08/10/dlib/的步骤,但当我尝试运行(我使用sudo),
python python_examples/face_detector.py examples/faces/2007_007763.jpg
收回错误.
首先,错误是
AttributeError: 'module' object has no attribute 'image_window'
到第8行.
现在,错误是非法指令(核心转储),但我不知道为什么.
请帮我正确添加库.
import sys
import dlib
from skimage import io
detector = dlib.get_frontal_face_detector()
win = dlib.image_window()
for f in sys.argv[1:]:
print("Processing file: {}".format(f))
img = io.imread(f)
# The 1 in the second argument indicates that we should upsample the image
# 1 time. This will make everything bigger and allow us to detect more
# faces.
dets = detector(img, 1)
print("Number of faces detected: {}".format(len(dets)))
for i, d in enumerate(dets):
print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
i, d.left(), d.top(), d.right(), d.bottom()))
win.clear_overlay()
win.set_image(img)
win.add_overlay(dets)
dlib.hit_enter_to_continue()
# Finally, if you really want to you can ask the detector to tell you the score
# for each detection. The score is bigger for more confident detections.
# The third argument to run is an optional adjustment to the detection threshold,
# where a negative value will return more detections and a positive value fewer.
# Also, the idx tells you which of the face sub-detectors matched. This can be
# used to broadly identify faces in different orientations.
if (len(sys.argv[1:]) > 0):
img = io.imread(sys.argv[1])
dets, scores, idx = detector.run(img, 1, -1)
for i, d in enumerate(dets):
print("Detection {}, score: {}, face_type:{}".format(
d, scores[i], idx[i]))
解决方法:
正如我在你的代码中看到的:
detector = dlib.get_frontal_face_detector()
win = dlib.image_window()
第一行有效,第二行没有.这意味着已安装dlib,但它在没有GUI支持的情况下进行编译
In dlib’s source code我们看到如果定义了宏DLIB_NO_GUI_SUPPORT – dlib模块中将没有“image_window”函数.如果CMake脚本找不到X11库,则会自动定义此宏
您需要确保使用GUI支持编译dlib.要做到这一点,首先 – 如果您正在使用Linux或XQuartz for Mac,请将libx11-dev安装到您的系统中
当使用运行python setup.py install构建dlib时 – 以及DLIB_JPEG_SUPPORT – 检查其消息.如果有错误或警告 – 修复它们