2017-09-17 4 views
1

Dlibs imutils.face_utilsを使用して顔認識を行う前に、Dlibのrectに変換することで顔を整列しようとしています。しかし、私はgettngエラー矩形を保持しないiterableです。ここ は、私がDLIB FaceUtilsを用いて、第1整列させ、その後、OpenCVののrecognizer.predict()を使用して予測を行うにはどうすればよいコードTypeError: 'rectangle'オブジェクトは、顔の整列後に反復できません。Dlib FaceUtils

detector = dlib.get_frontal_face_detector() 
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") 

fa = FaceAligner(predictor) 

のですか?

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

DLIB矩形オブジェクトが反復可能ではない、

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 
にループのためにあなたを変更
関連する問題