AttributeError: 'module' object has no attribute 'get_frontal_face_detector'
AttributeError: 'module' object has no attribute 'get_frontal_face_detector'
我正在尝试使用 python 的 dlib 库来检测面部标志。我正在使用 face detector 上给出的示例。我在安装dlib之前已经安装了所有的依赖。
首先,我使用 "sudo apt-get install libboost-python-dev cmake" 安装了 cmake 和 libboost,如上文 link 所示。然后我使用 "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'
这是我的项目的目录结构:
将您的文件从 dlib.py
重命名为其他名称,比如 dlib_project.py
。
您的如此命名的文件正在隐藏具有您需要的所有功能的 dlib
库,因为它是导入的而不是库,在层次结构中位于第一个。
我正在尝试使用 python 的 dlib 库来检测面部标志。我正在使用 face detector 上给出的示例。我在安装dlib之前已经安装了所有的依赖。
首先,我使用 "sudo apt-get install libboost-python-dev cmake" 安装了 cmake 和 libboost,如上文 link 所示。然后我使用 "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'
这是我的项目的目录结构:
将您的文件从 dlib.py
重命名为其他名称,比如 dlib_project.py
。
您的如此命名的文件正在隐藏具有您需要的所有功能的 dlib
库,因为它是导入的而不是库,在层次结构中位于第一个。