识别基报数据
This commit is contained in:
parent
94eca0ebeb
commit
7643cf2dae
3 changed files with 86 additions and 77 deletions
|
@ -1,11 +1,14 @@
|
|||
from pepperbot.core.message.chain import MessageChain, Image, Text
|
||||
from paddleocr import PaddleOCR
|
||||
from rapidocr_onnxruntime import RapidOCR
|
||||
import os
|
||||
import asyncio
|
||||
import functools
|
||||
import re
|
||||
|
||||
|
||||
ocr = PaddleOCR(use_angle_cls=False, use_gpu=False)
|
||||
rapid_ocr = None
|
||||
if not rapid_ocr:
|
||||
rapid_ocr = RapidOCR("rapid_ocr.yml")
|
||||
|
||||
|
||||
class RIICReportAnalysis:
|
||||
|
@ -14,14 +17,50 @@ class RIICReportAnalysis:
|
|||
return
|
||||
img_seg: Image = chain[0]
|
||||
img_path = await img_seg.download()
|
||||
print(f"Image saved to {img_path}")
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
ocr_text = await loop.run_in_executor(
|
||||
None, functools.partial(ocr.ocr, img_path, cls=False)
|
||||
result, elapse = await loop.run_in_executor(
|
||||
None, functools.partial(rapid_ocr, img_path)
|
||||
)
|
||||
print(ocr_text)
|
||||
if not "副手简报" in [i[1] for i in result]:
|
||||
return
|
||||
lmb_height = 0
|
||||
lmb_numers = []
|
||||
date_list = []
|
||||
exp_list = []
|
||||
gold_list = []
|
||||
for i in result:
|
||||
if i[1] == "龙门币":
|
||||
lmb_height = i[0][0][1]
|
||||
break
|
||||
for i in result:
|
||||
if m := re.search(r"([0-9]+\.[0-9]+)", i[1]):
|
||||
date_list.append([int(i[0][0][0]), m.group(1)])
|
||||
continue
|
||||
if m := re.search(r"EXP([0-9]+)的作战记录", i[1]):
|
||||
exp_list.append([int(i[0][0][0]), m.group(1)])
|
||||
continue
|
||||
if m := re.search(r"([0-9]+)的贵金属", i[1]):
|
||||
gold_list.append([int(i[0][0][0]), m.group(1)])
|
||||
continue
|
||||
if lmb_height - 20 < i[0][0][1] < lmb_height + 20:
|
||||
if m := re.search(r"([0-9]+)", i[1]):
|
||||
lmb_numers.append([int(i[0][0][0]), m.group(1)])
|
||||
|
||||
lmb_numers.sort(key=lambda x: x[0])
|
||||
gold_list.sort(key=lambda x: x[0])
|
||||
exp_list.sort(key=lambda x: x[0])
|
||||
date_list.sort(key=lambda x: x[0])
|
||||
|
||||
output = ""
|
||||
|
||||
for i in range(len(date_list)):
|
||||
output += f"【{date_list[i][1]}】\n"
|
||||
output += f"💵 {lmb_numers[2 * i][1]}订单({lmb_numers[2 * i + 1][1]})\n"
|
||||
output += f"🧈 {gold_list[i][1]}赤金\n"
|
||||
output += f"📼 {exp_list[i][1]}经验\n\n"
|
||||
|
||||
await chain.onebot_reply(Text(output.strip()))
|
||||
|
||||
os.remove(img_path)
|
||||
print(f"file removed.")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue