运行Dlib Face检测时非法指令(核心转储)

时间:2016-06-19 06:17:37

标签: python face-detection coredump dlib

我正在尝试运行由Dlib库提供的face_landmark_detection.py示例示例。

但是当我试图通过ubuntu终端运行命令时,我收到错误:

Illegal instruction (core dumped)

我调试它,所以我知道这是因为这一行:

win=dlib.image_window()

我猜这条线路有问题

我正在通过此命令运行代码:

./ face_landmark_detection.py /home/abhishek/openCV/shape_predictor_68_face_landmarks.dat ../ examples / faces

正如示例代码中所做的那样。 我的代码

        import sys
        import os
        import dlib
        import glob
        from skimage import io

        if len(sys.argv) != 3:
        print(
    "Give the path to the trained shape predictor model as the first "
    "argument and then the directory containing the facial images.\n"
    "For example, if you are in the python_examples folder then "
    "execute this program by running:\n"
    "    ./face_landmark_detection.py shape_predictor_68_face_landmarks.dat ../examples/faces\n"
    "You can download a trained facial shape predictor from:\n"
    "    http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2")
            exit()

        predictor_path = sys.argv[1]
        faces_folder_path = sys.argv[2]

        print predictor_path
        print faces_folder_path

        detector = dlib.get_frontal_face_detector()
        predictor = dlib.shape_predictor(predictor_path)
        win = dlib.image_window()


        for f in glob.glob(os.path.join(faces_folder_path, "*.jpg")):

             print("Processing file: {}".format(f))
             img = io.imread(f)

             print "img",img
             win.clear_overlay()
             win.set_image(img)

# Ask the detector to find the bounding boxes of each face. 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 k, d in enumerate(dets):
               print("Detection {}: Left: {} Top: {} Right: {} Bottom:             {}".format(
        k, d.left(), d.top(), d.right(), d.bottom()))
    # Get the landmarks/parts for the face in box d.
            shape = predictor(img, d)
            print("Part 0: {}, Part 1: {} ...".format(shape.part(0),
                                              shape.part(1)))
    # Draw the face landmarks on the screen.
           win.add_overlay(shape)

    win.add_overlay(dets)
    dlib.hit_enter_to_continue()

2 个答案:

答案 0 :(得分:2)

看起来dlib无法在您的情况下创建图像窗口。可能的原因 - 不正确的dlib安装。正如Dlib的文档描述(readme.txt),您应该通过运行setup.py来安装它:

COMPILING DLIB Python API
   Before you can run the Python example programs you must compile dlib. Type:
       python setup.py install
   or type
       python setup.py install --yes USE_AVX_INSTRUCTIONS
   if you have a CPU that supports AVX instructions, since this makes some
   things run faster.  

在运行setup.py之前,你还需要安装libx11-dev(sudo apt-get install libx11-dev)

检查安装脚本消息以查看任何可能的错误,如果您看到它们 - 更新您的问题以描述情况

答案 1 :(得分:1)

我刚刚遇到这个问题,因为python模块是用SSE4指令编译的,但我的CPU只支持SSE2。打开工具/ python / CMakeLists.txt并编辑行

1.5+

在我的情况下,我将其更改为

set(USE_SSE4_INSTRUCTIONS ON CACHE BOOL "Use SSE4 instructions")