commit 40069c71afca2414d82a2b29bd44f27dc59e31d5 Author: Cx330 <1487537121@qq.com> Date: Sat May 17 12:54:11 2025 +0800 v0.0.1 diff --git a/file/zj.jpg b/file/zj.jpg new file mode 100644 index 0000000..b758c7b Binary files /dev/null and b/file/zj.jpg differ diff --git a/recognition.py b/recognition.py new file mode 100644 index 0000000..d9ceba9 --- /dev/null +++ b/recognition.py @@ -0,0 +1,97 @@ +import cv2 +import easyocr +import matplotlib.pyplot as plt +plt.rcParams['font.sans-serif'] = ['simHei'] +plt.rcParams['axes.unicode_minus'] = False + +reader = easyocr.Reader(['ch_sim'], gpu=False) +image = cv2.imread('file/zj.jpg') + +# 所有要提取的坐标区域 +id = [ + (460, 415, 800, 460), + (460, 610, 800, 655), + (550, 805, 800, 850), + (460, 995, 800, 1040), + (460, 1190, 800, 1235), + + (1860, 415, 2200, 460), + (1930, 610, 2200, 655), + (1860, 805, 2200, 850), + (1930, 995, 2200, 1040), + (1860, 1190, 2200, 1235), +] + +score = [ + (335, 488, 465, 545), + (335, 680, 465, 740), + (335, 875, 465, 930), + (335, 1070, 465, 1125), + (335, 1260, 465, 1320), + + (1710, 488, 1845, 545), + (1710, 680, 1845, 740), + (1710, 875, 1845, 930), + (1710, 1070, 1845, 1125), + (1710, 1260, 1845, 1320), +] + +# 提取图像区域并转换为RGB +images_rgb_id = [] +images_rgb_score = [] +results_id = [] +results_score = [] + +for (x1, y1, x2, y2) in id: + cropped = image[y1:y2, x1:x2] + rgb = cv2.cvtColor(cropped, cv2.COLOR_BGR2RGB) + images_rgb_id.append(rgb) + results_id.append(reader.readtext(rgb, detail=0)) + +for (x1, y1, x2, y2) in score: + cropped = image[y1:y2, x1:x2] + rgb = cv2.cvtColor(cropped, cv2.COLOR_BGR2RGB) + images_rgb_score.append(rgb) + results_score.append(reader.readtext(rgb, detail=0)) + +# 打印结果 +for i, result in enumerate(results_id, 1): + print(f"result{i}:", result) + +for i, result in enumerate(results_score, 1): + print(f"result{i}:", result) + +# 显示图像 +plt.figure(figsize=(10, 15)) +for i, img in enumerate(images_rgb_id, 1): + plt.subplot(5, 2, i) + plt.imshow(img) + plt.title('测试') + plt.axis('off') + +plt.figure(figsize=(10, 15)) +for i, img in enumerate(images_rgb_score, 1): + plt.subplot(5, 2, i) + plt.imshow(img) + plt.title('测试') + 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