TypeError:字符串索引必须是整数,而不是str人脸识别

时间:2018-07-24 17:29:50

标签: python arrays

所以我正在使用应该打开我的摄像头并进行人脸识别的代码,但这就是你

(facecourse-py2) lawn-128-61-17-230:face-recognition-opencv apaar$ 

python recognize_faces_video.py --encodings encodings.pickle --output output/webcam_face_recognition_output.avi --display 1
[INFO] loading encodings...
[INFO] starting video stream...
Traceback (most recent call last):
  File "recognize_faces_video.py", line 60, in <module>
    matches = int(face_recognition.compare_faces(data["encodings"],
TypeError: string indices must be integers, not str

第60行的代码如下:

    for encoding in encodings:
    # attempt to match each face in the input image to our known
    # encodings
    matches = int(face_recognition.compare_faces(data["encodings"],
        encoding))
    name = "Unknown"

1 个答案:

答案 0 :(得分:0)

在评论部分,您说您将data初始化为

data = pickle.dumps(open(args["encodings"], "rb").read()) 

这将返回一个string,您尝试使用另一个string来访问它,

data["encodings"]

因此出现错误。