【发布时间】:2019-10-12 20:06:04
【问题描述】:
在这段代码中使用了 dlib 的检测器。
dlib.get_frontal_face_detector() dlib.cnn_face_detection_model_v1('mmod_human_face_detector.dat')
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('res/model.dat')
# detector = dlib.cnn_face_detection_model_v1('mmod_human_face_detector.dat')
cap = cv.VideoCapture(0)
while True:
_, frame = cap.read(0)
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
dets = detector(gray, 0)
print(dets)
for det in dets:
landmarks = shape_to_np(predictor(gray, det))
cv.imshow('test', frame)
if cv.waitKey(1) == ord('q'):
break
当使用 cnn 检测器时,dets 看起来像:
mmod_rectangles[[(258, 254) (422, 417)]]
并且在预测器行中抛出异常:
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 0x7f37a12ba9d0>,
array([[71, 69, 70, ..., 71, 70, 73],
[71, 72, 71, ..., 72, 72, 75],
[71, 70, 71, ..., 72, 72, 73],
...,
[27, 27, 27, ..., 75, 71, 68],
[27, 27, 27, ..., 74, 71, 71],
[24, 25, 27, ..., 73, 71, 70]], dtype=uint8), <dlib.mmod_rectangle object at 0x7f37819beea0>
但是当使用 get_frontal_face_detector 时,dets 看起来像:
rectangles[[(273, 234) (453, 413)]]
并且代码可以正常工作。
【问题讨论】:
标签: python-3.x dlib