我试图通过将OpenCV rect转换为Dlib的rect来使用Dlibs imutils.face_utils
在面部识别之前对齐面部。但我保持gettng错误矩形是不可迭代的。
这是代码
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
fa = FaceAligner(predictor)
如何首先使用Dlib FaceUtils对齐,然后使用OpenCV的recognizer.predict()
进行预测?
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = detector(gray, 2)
# If faces are found, try to recognize them
for (x,y,w,h) in faces:
(x1, y1, w1, h1) = rect_to_bb(x,y,w,h)
faceAligned = fa.align(image, gray, (x1,y1,w1,h1))
label, confidence = recognizer.predict(faceAligned)
if confidence < threshold:
found_faces.append((label, confidence, (x, y, w, h)))
return found_faces
答案 0 :(得分:1)
dlib矩形对象不可迭代,将for循环更改为
for face in faces:
x = face.left()
y = face.top() #could be face.bottom() - not sure
w = face.right() - face.left()
h = face.bottom() - face.top()
(x1, y1, w1, h1) = rect_to_bb(x,y,w,h)
# rest same as above