问题:使用Dlib cnn模型进行人脸检测时报错
在使用Dlib进行人脸识别时,使用基于HOG的dlib.get_frontal_face_detector()可以正常运行,但当使用基于cnn的dlib.cnn_face_detection_model_v1(‘’)时,会报TypeError: call(): incompatible function arguments. The following argument types are supported:
1. (self: _dlib_pybind11.shape_predictor, image: array, box: _dlib_pybind11.rectangle) -> _dlib_pybind11.full_object_detection的错误
原因:
传入格式不对,box格式应该是 rectangles,但错误输入mmod_rectangles的格式
解决方法:
转换格式,在参数后面加“.rect”
如:
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
cnn_face_detector = dlib.cnn_face_detection_model_v1('mmod_human_face_detector.dat')
face_detector = cnn_face_detector(img_camera, 1)
face_predictor = predictor(img_camera, face_detector[0].rect)