AttributeError:“模块"对象没有属性"get_frontal_face_detector" [英] AttributeError: 'module' object has no attribute 'get_frontal_face_detector'

查看:1038
本文介绍了AttributeError:“模块"对象没有属性"get_frontal_face_detector"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用python的dlib库来检测面部标志.我使用的是人脸检测器上给出的示例.在安装dlib之前,我已经安装了所有依赖项.

I was trying to use python's dlib library to detect the facial landmarks. I was using the example given on face detector. I have installed all the dependencies before installing dlib.

首先,我使用上面链接中给出的"sudo apt-get install libboost-python-dev cmake"安装了cmake和libboost.然后,我使用"pip install dlib"安装了dlib.

First I installed cmake and libboost using "sudo apt-get install libboost-python-dev cmake" as given on the link above. I then installed dlib using "pip install dlib".

我的代码:

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

predictor_path = 'shape_predictor_68_face_landmarks.dat'
faces_folder_path = './happy'
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)

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

但是当我运行程序时,出现以下错误:

But when I run the program, I get the following error:

Traceback (most recent call last):
  File "dlib.py", line 2, in <module>
    import dlib
  File "/home/shivam/musicplayer/dlib.py", line 6, in <module>
    detector = dlib.get_frontal_face_detector() #Face detector
AttributeError: 'module' object has no attribute 'get_frontal_face_detector'

这是我的项目的目录结构:

Here is the directory structure of my project:

推荐答案

将文件从dlib.py重命名为其他名称,例如dlib_project.py.

Rename your file from dlib.py to something else, say dlib_project.py.

您的文件名如此,它隐藏了具有所有所需功能的dlib库,因为它是导入的而不是库,它是层次结构中的第一位.

Your file, named so, is shadowing the dlib library that has all of the functionality you need, as it is imported instead of the library, being first in the hierarchy.

这篇关于AttributeError:“模块"对象没有属性"get_frontal_face_detector"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆