我想使用Python软件包----“ dlib”来检测图片中的人脸,当我使用“ detector = dlib.get_frontal_face_detector()”作为检测器时,没有错误,我可以获得人脸图片。但是当我使用“ detector = dlib.cnn_face_detection_model_v1”作为检测器时,会出现一些错误。在两种情况下,预测变量都是“ shape_predictor_68_face_landmarks.dat”。
我使用DEBUG查找导致错误的代码,并且在运行代码“ shape = dictoror(frame,d)”时发现错误:
Traceback (most recent call last):
File "/home/cxd/pycharm-community-2019.1/helpers/pydev/pydevd.py", line 1741, in <module>
main()
File "/home/cxd/pycharm-community-2019.1/helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/cxd/pycharm-community-2019.1/helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/cxd/PycharmProjects/ROI/videos.py", line 47, in get_frames_mouth
shape = predictor(frame, d)
TypeError: __call__(): incompatible function arguments. The following argument types are supported:
1. (self: dlib.shape_predictor, image: array, box: dlib.rectangle) -> dlib.full_object_detection
Invoked with: <dlib.shape_predictor object at 0x7f17f3684ce0>, array([[[124, 106, 145],
[124, 106, 145],
[124, 106, 145],
...,
[134, 116, 145],
[134, 116, 145],
[134, 116, 145]],
[[124, 106, 145],
[124, 106, 145],
[124, 106, 145],
...,
[134, 116, 145],
[134, 116, 145],
[134, 116, 145]],
[[124, 106, 145],
[124, 106, 145],
[124, 106, 145],
...,
[134, 115, 147],
[134, 115, 147],
[134, 115, 147]],
...,
[[ 37, 0, 1],
[ 37, 0, 1],
[ 36, 0, 0],
...,
[ 56, 0, 17],
[ 55, 0, 17],
[ 55, 0, 17]],
[[ 37, 0, 0],
[ 36, 0, 0],
[ 36, 0, 0],
...,
[ 55, 0, 16],
[ 54, 0, 16],
[ 54, 0, 16]],
[[ 37, 0, 0],
[ 36, 0, 0],
[ 36, 0, 0],
...,
[ 55, 0, 16],
[ 54, 0, 16],
[ 54, 0, 16]]], dtype=uint8), <dlib.mmod_rectangle object at 0x7f18250c7308>
Process finished with exit code 1
代码是:
detector = dlib.cnn_face_detection_model_v1("mmod_human_face_detector.dat")
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
dets = detector(frame, 1) #frame is np.array
shape = None
for k, d in enumerate(dets):
shape = predictor(frame, d)
我认为两种检测器的结果相同,有人可以帮助我解决这个问题吗?