From d3fdae1013a1618376e3e751b5e0008249fd63b4 Mon Sep 17 00:00:00 2001 From: Cx330 <1487537121@qq.com> Date: Sat, 17 May 2025 16:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BE=93=E5=87=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- recognition.py | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/recognition.py b/recognition.py index 5228701..e6c2989 100644 --- a/recognition.py +++ b/recognition.py @@ -55,11 +55,26 @@ for (x1, y1, x2, y2) in score: results_score.append(reader.readtext(rgb, detail=0)) # 打印结果 -for i, result in enumerate(results_id, 1): - print(f"玩家{i}名称:", result) +for i, (player_id, player_score) in enumerate(zip(results_id, results_score), 1): + print(f"玩家{i}", player_id, f"的评分为:", player_score) + # print(f"玩家{i}游戏评分:", score) -for i, result in enumerate(results_score, 1): - print(f"玩家{i}游戏评分:", result) +# 找出最高评分玩家 +max_val = 0.0 +max_idx = 0 +for i, texts in enumerate(results_score): + if not texts: + continue + try: + val = float(texts[0]) + except ValueError: + continue + if val > max_val: + max_val = val + max_idx = i + +print("全场最高分:", max_val) +print("全场最佳玩家ID:", results_id[max_idx]) # 显示图像 plt.figure(figsize=(8, 6)) @@ -77,21 +92,4 @@ for i, img in enumerate(images_rgb_score, 1): plt.axis('off') plt.tight_layout() -plt.show() - -# 找出最高评分玩家 -max_val = 0.0 -max_idx = 0 -for i, texts in enumerate(results_score): - if not texts: - continue - try: - val = float(texts[0]) - except ValueError: - continue - if val > max_val: - max_val = val - max_idx = i - -print("最高评分:", max_val) -print("最高评分玩家ID:", results_id[max_idx]) \ No newline at end of file +plt.show() \ No newline at end of file