python - 类型错误 : 'rectangle' object is not iterable after face alignment usinf Dlib FaceUtils

标签 python opencv dlib

我试图通过将 OpenCV 矩形转换为 Dlib 的矩形,在使用 Dlibs imutils.face_utils 进行人脸识别之前对齐人脸。但我不断收到错误 rectangle is not iterable。 这是代码

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

最佳答案

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

关于python - 类型错误 : 'rectangle' object is not iterable after face alignment usinf Dlib FaceUtils,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46261185/

相关文章:

c++ - 如何为多车道检测过滤霍夫线?

c++ - 编译时出现错误 "fopen' : This function or variable may be unsafe.

python - OpenCV “imshow”函数可打开许多窗口,而不是替换一个窗口上的框架-Python

c++ - 无法从 mmod 面部检测器获取 dlib 矩形坐标

python - Python中的阶乘函数

python - 即使使用 Auth Pre-Flight 的头,Python Falcon 的 CORS 失败

javascript - Python 中是否有类似于 Harmony 的 let 关键字的东西?

python - sqlalchemy "after_update"事件后级联更新

python - 在OpenCV上输入高分辨率视频文件时,fps较低

python-3.x - 没有名为 'dlib' 的模块