python版本 微信ocr调用

pip install wechat-ocr
import base64
import os
import json
import time
from wechat_ocr.ocr_manager import OcrManager, OCR_MAX_TASK_ID
from yscredit_tools.utils import md5string
wechat_ocr_dir = r"C:\Users\YS\AppData\Roaming\Tencent\WeChat\XPlugin\Plugins\WeChatOCR\7079\extracted\WeChatOCR.exe"
wechat_dir = "C:\Program Files (x86)\Tencent\WeChat\[3.9.10.19]"


def ocr_result_callback(img_path:str, results:dict):
    print(results["ocrResult"])
    # results["img_path"] = img_path
    # with open('1.yaml', 'a', encoding='utf-8') as f:
    #    f.write(json.dumps(results, ensure_ascii=False, indent=2))
    #    f.write('\n')
def main(ocr_manager,image_paths):
    for image_path in image_paths:
        ocr_manager.DoOCRTask(image_path)
    print('任务长度: ',ocr_manager.m_task_id.qsize())
    while ocr_manager.m_task_id.qsize() != OCR_MAX_TASK_ID:
        pass
    # 识别输出结果
    print('???')
    ocr_manager.KillWeChatOCR()


if __name__ == "__main__":
    ocr_manager = OcrManager(wechat_dir)
    # 设置WeChatOcr目录
    ocr_manager.SetExePath(wechat_ocr_dir)
    # 设置微信所在路径
    ocr_manager.SetUsrLibDir(wechat_dir)
    # 设置ocr识别结果的回调函数
    ocr_manager.SetOcrResultCallback(ocr_result_callback)
    # 启动ocr服务
    ocr_manager.StartWeChatOCR()
    code_lst = []
    image_paths = []
    # for code in code_lst:
    #     code = base64.b64decode(code.split(':')[1])
    #     name = md5string(code)
    #     with open(f'./img/{name}.png','wb') as f:
    #         f.write(code)
    #     image_paths.append(f'./img/{md5string(code)}.png')
    image_paths.append(f'./img/img.png')
    main(ocr_manager,image_paths)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰吸生椰拿铁.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值