From 192b583d19520587a37916e156fa5472ffebd200 Mon Sep 17 00:00:00 2001 From: AzureRubia <97378825+AzureRubia-Guet@users.noreply.github.com> Date: Tue, 10 Oct 2023 23:21:11 +0800 Subject: [PATCH] Update demo_face_recognization.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对于寻找kpu.face_compare函数的得分列表中的最高得分,使用内置的max函数与list的index函数精简了代码。 --- .../face_recognization/demo_face_recognization.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/machine_vision/face_recognization/demo_face_recognization.py b/machine_vision/face_recognization/demo_face_recognization.py index a9e03d0..14188aa 100644 --- a/machine_vision/face_recognization/demo_face_recognization.py +++ b/machine_vision/face_recognization/demo_face_recognization.py @@ -92,12 +92,9 @@ def set_key_state(*_): for j in range(len(record_ftrs)): score = kpu.face_compare(record_ftrs[j], feature) scores.append(score) - max_score = 0 - index = 0 - for k in range(len(scores)): - if max_score < scores[k]: - max_score = scores[k] - index = k + else: + max_score = max(scores) + index = scores.index(max_score) if max_score > ACCURACY: a = img.draw_string(i.x(), i.y(), ("%s :%2.1f" % ( names[index], max_score)), color=(0, 255, 0), scale=2)