TypeError: tuple indices must be integers or slices, not str, when using MTCNN
TypeError: tuple indices must be integers or slices, not str, when using MTCNN
当我想访问以下元组时出现以下错误
[{'box': [215, 102, 179, 238],
'confidence': 0.999460756778717,
'keypoints': {'left_eye': (277, 193),
'mouth_left': (287, 284),
'mouth_right': (356, 283),
'nose': (330, 239),
'right_eye': (361, 191)}}]
for person in face_locations:
bounding_box = person['box'] #in this line I get the error
keypoints = person['keypoints']
cv2.rectangle(img_final,
(bounding_box[0], bounding_box[1]),
(bounding_box[0]+bounding_box[2], bounding_box[1] + bounding_box[3]),
(0,155,255),
2)
cv2.circle(img_final,(keypoints['left_eye']), 2, (0,155,255), 2)
cv2.circle(img_final,(keypoints['right_eye']), 2, (0,155,255), 2)
cv2.circle(img_final,(keypoints['nose']), 2, (0,155,255), 2)
cv2.circle(img_final,(keypoints['mouth_left']), 2, (0,155,255), 2)
cv2.circle(img_final,(keypoints['mouth_right']), 2, (0,155,255), 2)
而不是这个:
for person in face_locations:
bounding_box = person['box']
keypoints = person['keypoints']
你应该这样做:
person = face_locations[0]
bounding_box = person['box']
keypoints = person['keypoints']
print(bounding_box, keypoints)
结果:
[`215, 102, 179, 238]`
{'left_eye': (277, 193), 'mouth_left': (287, 284), 'mouth_right': (356, 283), 'nose': (330, 239), 'right_eye': (361, 191)}
当我想访问以下元组时出现以下错误
[{'box': [215, 102, 179, 238], 'confidence': 0.999460756778717, 'keypoints': {'left_eye': (277, 193), 'mouth_left': (287, 284), 'mouth_right': (356, 283), 'nose': (330, 239), 'right_eye': (361, 191)}}]
for person in face_locations:
bounding_box = person['box'] #in this line I get the error
keypoints = person['keypoints']
cv2.rectangle(img_final,
(bounding_box[0], bounding_box[1]),
(bounding_box[0]+bounding_box[2], bounding_box[1] + bounding_box[3]),
(0,155,255),
2)
cv2.circle(img_final,(keypoints['left_eye']), 2, (0,155,255), 2)
cv2.circle(img_final,(keypoints['right_eye']), 2, (0,155,255), 2)
cv2.circle(img_final,(keypoints['nose']), 2, (0,155,255), 2)
cv2.circle(img_final,(keypoints['mouth_left']), 2, (0,155,255), 2)
cv2.circle(img_final,(keypoints['mouth_right']), 2, (0,155,255), 2)
而不是这个:
for person in face_locations:
bounding_box = person['box']
keypoints = person['keypoints']
你应该这样做:
person = face_locations[0]
bounding_box = person['box']
keypoints = person['keypoints']
print(bounding_box, keypoints)
结果:
[`215, 102, 179, 238]`
{'left_eye': (277, 193), 'mouth_left': (287, 284), 'mouth_right': (356, 283), 'nose': (330, 239), 'right_eye': (361, 191)}