python - 运行 Dlib 人脸检测时出现非法指令(核心转储)

标签 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()

最佳答案

看起来 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)

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

关于python - 运行 Dlib 人脸检测时出现非法指令(核心转储),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37904503/

相关文章:

python - Project Euler #25 Python 为什么这行不通?

python - 在 Python 2.6 中加载时维护 JSON 文件的键顺序

android - 浏览图像和人脸检测

ios - UIImage 人脸检测

opencv - 使用 OpenCV 对非正面图像进行人脸检测

ubuntu - 在 Ubuntu 18.04 和 Ubuntu 20.04 中找不到核心转储文件

带有 SIGFPE 的核心转储用于非零除法

python - 独特页面的数据框摘要

python - 在 python nostests 覆盖率报告中显示没有单元测试的文件

c - Unix 上的段错误 - 可能的堆栈损坏