Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

attributeerror - Error to run a library to python

I follow the steps according to http://npatta01.github.io/2015/08/10/dlib/ but when I try to run (I use sudo),

python python_examples/face_detector.py examples/faces/2007_007763.jpg

take back error. Firstly, the error was

AttributeError: 'module' object has no attribute 'image_window' 

to line 8. Now, the error is Illegal instruction (core dumped) but I don't know why. Please, help me to add the library correctly.

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]))
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As I see in your code:

detector = dlib.get_frontal_face_detector()
win = dlib.image_window()

First line works and the second does not. This means that dlib is installed, but it is compiled with no GUI support

In dlib's source code we see that if macro DLIB_NO_GUI_SUPPORT is defined - there will be no "image_window" function in dlib module. This macro is defined automatically if CMake scripts can't find X11 libraries

You need to ensure that dlib is compiled with GUI support. To make it, first - install libx11-dev into your system if you are working on Linux, or XQuartz for Mac

When building dlib with running python setup.py install --yes DLIB_JPEG_SUPPORT - check its messages. If there are errors or warnings - fix them


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...