【问题标题】:face_recognition error: list index out of rangeface_recognition 错误:列表索引超出范围
【发布时间】:2021-06-08 08:12:26
【问题描述】:

我已经阅读了这个错误并且大多数人认为这意味着 face_recognition 没有检测到帧中的任何人脸。但是,open cv 正在同一帧内检测人脸,所以我不确定 face_recognition 是否确实没有检测到任何人脸,或者由于其他原因我收到了 IndexError?

img=face_recognition.load_image_file('Roman.jpg')

roman_encoding = face_recognition.face_encodings(img)[0]

group_locations = face_recognition.face_locations(group_image)

group_encodings = face_recognition.face_encodings(group_image)
size = len(group_encodings)

print("total faces "+str(size))
k = 0

for x in group_encodings:
  results = face_recognition.compare_faces([roman_encodings], x)
  if results == True:
    print("Face"+str(size-k)+"at",end='')
    print(group_locations)
  k+=1

它在 roman_encoding = face_recognition.face_encodings(img)[0] 处抛出列表索引超出范围错误

我在其他地方使用过相同的图像,效果非常好。

【问题讨论】:

    标签: face-recognition


    【解决方案1】:

    您好,这个方法是先检测人脸,然后根据准确率百分比进行识别。这对我来说效果很好

    bounding_boxes, _ = detect_face.detect_face(frame, minsize, pnet, rnet, onet, threshold, factor)
    nrof_faces = bounding_boxes.shape[0]
    if nrof_faces > 0:
        det = bounding_boxes[:, 0:4]
        img_size = np.asarray(frame.shape)[0:2]
        cropped = []
        scaled = []
        scaled_reshape = []
        bb = np.zeros((nrof_faces,4), dtype=np.int32)
        for i in range(nrof_faces):
            #<Code for frame manipulation>
            predictions = model.predict_proba(emb_array)
            best_class_indices = np.argmax(predictions, axis=1)
            best_class_probabilities = predictions[np.arange(len(best_class_indices)), best_class_indices]
            # print(best_class_probabilities)
            if best_class_probabilities>0.6:
                #<detect as face>
    

    【讨论】:

      猜你喜欢
      • 2020-05-12
      • 1970-01-01
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      相关资源
      最近更新 更多