face_recognition错误:列表索引超出范围



我仔细研究了这个错误,大多数人得出的结论是,这意味着face_recognition没有检测到帧中的任何人脸。然而,开放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]抛出列表索引超出范围错误

我在其他地方使用了相同的图像,它工作得很好。

我用这种方法先检测人脸,然后根据准确率百分比进行识别。这对我来说很有效

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>

相关内容

  • 没有找到相关文章

最新更新