2016-09-27 91 views
1

我按照步骤根据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行 现在,误差为Illegal instruction (core dumped),但我不知道为什么。 请帮助我正确地添加库。

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])) 
+0

你可以发布你的代码吗?发生的事情是,您正试图在另一个模块中访问名为image_window的函数或对象,但它不存在。 –

+0

欢迎来到StackOverflow。请阅读并遵守帮助文档中的发布准则。 [最小,完整,可验证的示例](http://stackoverflow.com/help/mcve)适用于此处。在您发布代码并准确描述问题之前,我们无法有效帮助您。 – Prune

+0

既然你没有充分描述你开始做什么,也没有你改变什么,也没有提供完整的错误信息,我们真的不能帮助。 – Prune

回答

0

正如我在你的代码中看到:

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库,则自动定义此宏。

您需要确保dlib是在GUI支持下编译的。要做到这一点,首先将libx11-dev安装到您的系统中,如果您正在使用Linux或XQuartz for Mac

在运行python setup.py install --yes DLIB_JPEG_SUPPORT时构建dlib - 检查其消息。如果有错误或警告 - 修复它们

+0

你说得对。来自'python setup.py install -yes DLIB_JPEG_SUPPORT'的消息是/ home/ekotsoni/dlib/dlib/cmake_utils/add_python_module中的CMake错误:115(消息): 未找到Boost python库。 调用堆栈(最近呼叫优先): CMakeLists.txt:6(包括) - 配置不完整,发生错误! 另请参阅“/home/ekotsoni/dlib/tools/python/build/CMakeFiles/CMakeOutput.log”。 错误:cmake配置失败!'我该做什么? – Eleftheria

+0

sudo apt-get install libboost-python-dev – Evgeniy

0

,因为我遇到了同样的问题,通过做

conda install -c conda-forge dlib 

pip install dlib 

我回答这个问题,我试着搜索,得到了一些有用的链接并在一个链接下方救了我的一天。所以在这里上市下来的细节太..

https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf

这将是更好的编译从GitHub最新的代码比畅达/ PIP安装。这是为了确保dlib是在GUI支持下编译的。

安装依附

sudo apt-get update

安装升压

sudo apt-get install libboost-all-dev 

安装其他依赖(可能是大部分将已经安装在系统中)

apt-get install -y --fix-missing  build-essential  cmake  gfortran  git  wget  curl  graphicsmagick  libgraphicsmagick1-dev  libatlas-dev  libavcodec-dev  libavformat-dev  libboost-all-dev  libgtk2.0-dev  libjpeg-dev  liblapack-dev  libswscale-dev  pkg-config  python3-dev  python3-numpy  software-properties-common zip 

apt-get clean 

构建来自Github的最新的dlib代码。假设: - Ubuntu 16。04或更高 - 没有了nVidia GPU不具备CUDA和cuDNN安装,不想GPU加速

克隆从GitHub代码:

git clone https://github.com/davisking/dlib.git 

构建主DLIB库:

cd dlib 
    mkdir build; cd build; cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1; cmake --build . 

建立和安装Python扩展:

cd .. 
    python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA 

确保指向正确的python(如果你在Ubuntu的vanilla python上安装了anaconda,那么你应该安装指向anaconda的包)。

,如果你仍然面临着gcc的错误,如下面

lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found 

然后确保你安装的是下面的Python包

conda install libgcc 

在这一点上,你应该能够运行Python和键入导入dlib成功。