python - 属性错误 : 'module' object has no attribute 'get_frontal_face_detector'

标签 python opencv dlib

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

首先,我使用上面链接中给出的“sudo apt-get install libboost-python-dev cmake”安装了 cmake 和 libboost。然后我使用“pip install dlib”安装了 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() 

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

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'

我的项目目录结构如下: enter image description here

最佳答案

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

你的文件,如此命名,正在隐藏具有你需要的所有功能的 dlib 库,因为它是导入的而不是库,在层次结构中是第一个。

关于python - 属性错误 : 'module' object has no attribute 'get_frontal_face_detector' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39518871/

相关文章:

OpenCV VideoWriter 使用带有 "Could not open codec ' libx26 4'"错误的 ffmpeg

tensorflow - 训练模型以实现 DLib 的面部标志,例如手部特征点及其标志

Python 子进程 readline() 挂起;不能使用普通选项

python - 如何小写字符串的第一个字符?

python - 如何在python中为linux设置复杂的环境变量?

c++ - 写入 InputOutputArray 抛出异常

python - 使utf8在文件中可读

python - 尝试 Django 迁移会生成错误 : "Unknown field(s) (groups) specified for User"

python - 如何解决与 Windows 10 上安装 dlib 相关的问题?

opencv - 训练分类器以仅检测睫毛/ Nose 功能dlib和opencv?