2023-08-13 19:42:17 +08:00
|
|
|
from pepperbot.core.message.chain import MessageChain, Image, Text
|
|
|
|
from paddleocr import PaddleOCR
|
|
|
|
import os
|
2023-08-13 18:31:28 +08:00
|
|
|
|
|
|
|
|
2023-08-13 20:05:54 +08:00
|
|
|
ocr = PaddleOCR(use_angle_cls=False, use_gpu=False)
|
|
|
|
|
|
|
|
|
2023-08-13 18:31:28 +08:00
|
|
|
class RIICReportAnalysis:
|
|
|
|
async def group_message(self, chain: MessageChain):
|
2023-08-13 19:50:02 +08:00
|
|
|
if len(chain) != 1 or len(chain.images) != 1:
|
2023-08-13 19:42:17 +08:00
|
|
|
return
|
|
|
|
img_seg: Image = chain[0]
|
|
|
|
img_path = await img_seg.download()
|
|
|
|
print(f"Image saved to {img_path}")
|
|
|
|
|
2023-08-13 20:05:54 +08:00
|
|
|
ocr_text = ocr.ocr(img_path, cls=False)
|
2023-08-13 19:42:17 +08:00
|
|
|
print(ocr_text)
|
|
|
|
|
|
|
|
os.remove(img_path)
|
|
|
|
print(f"file removed.")
|