GithubHelp home page GithubHelp logo

wechat_ocr's People

Contributors

kanadeblisst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wechat_ocr's Issues

回调函数可变参数扩展

下面这段代码中 ocr_result_callback 似乎没有办法设置 传参数量,默认一个 img_path 一个 result_json 没找到在哪改

def 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)


def ocr_result_callback(img_path:str, result_json:str, **args):
    result_json = EasyDict(result_json)

找到

    def CallUsrCallback(self, request_id:c_uint32, serialized_data: c_void_p, data_size: int):
        ocr_response_ubyte = (c_ubyte * data_size).from_address(serialized_data)
        ocr_response_array = bytearray(ocr_response_ubyte)
        ocr_response = ocr_protobuf_pb2.OcrResponse()
        ocr_response.ParseFromString(ocr_response_array)
        json_response_str = MessageToJson(ocr_response)
        task_id = ocr_response.task_id
        if not self.m_id_path.get(task_id):
            return
        #print(f"收到识别结果, task_id: {task_id}, result: {json_response}")
        pic_path = self.m_id_path[task_id]
        if self.m_usr_callback:
            self.m_usr_callback(pic_path, self.parse_json_response(json_response_str))
        self.SetTaskIdIdle(task_id)

self.m_usr_callback(pic_path, self.parse_json_response(json_response_str)) 改为
在初始化时候传参,不是源码里传参
能否改为 def test_kwargs(first, *args, **kwargs): 这样类型
目前个人是使用 ,**kwargs 但是还是不能传参,能否增加返回值的功能,就可以不使用全局变量来保存了

def ocr_result_callback(img_path:str, result_json:str,  www=1):
    result_json = EasyDict(result_json)

祝龙年大吉!

发来贺电,比其他那些什么ocr来的简单多了,谢谢!

作者大大,examples中可以添加一个读取json中的text内容的py文件,是否更加适合新手学习

其中的mode表示是否换行保存text内容。

import json
json_file = r"G:\Desktop\python小项目\调用微信ocr进行识别文字\2.png.json"
save_file = "save.txt"

def save_text(json_file, save_file, mode=1):
    # 打开 JSON 文件
    with open(json_file, 'r', encoding='utf-8') as file:
        # 从文件中加载 JSON 数据
        data = json.load(file)
    # 换行保存
    if mode == 1:
        with open(save_file, 'w', encoding='utf-8') as f:
            # 提取每个对象的 text 字段
            for item in data['ocrResult']:
                print(item['text'])
                f.write(item['text'] + '\n')
    # 不换行保存
    if mode == 2:
        with open(save_file, 'w', encoding='utf-8') as f:
            # 提取每个对象的 text 字段
            for item in data['ocrResult']:
                print(item['text'])
                f.write(item['text'])


save_text(json_file, save_file, mode=1)

demo运行成功, 但是结果的json文件里面是空的

demo运行成功, 但是结果的json文件里面是空的

(web) D:\ocr>python t.py
等待Ocr服务连接成功!
OCRRemoteOnConnect 回调函数被调用, 参数, is_connected: True
DefaultRemoteProcessLaunched 回调函数被调用
OCRReadOnPush 回调函数被调用 参数, request_id: 1, request_info: 46523088635872
OCRReadOnPush 回调函数被调用 参数, request_id: 1, request_info: 46523088636096
正在解析pb数据,pb数据大小: 15
img_path: D:\ocr\1.png, result_file: 1.png.json

结果如下

{
  "taskId": 1,
  "ocrResult": []
}

所使用的机器是windows server2016 不能上网,微信安装了没有使用, 不知道是不是这个原因,请大佬帮忙定位下😭

能否添加一个变量控制一下控制台的输出

调试通过之后,不希望在控制台中看到类似的日志打印输出:

OCRRemoteOnConnect 回调函数被调用, 参数, is_connected: True
DefaultRemoteProcessLaunched 回调函数被调用 
OCRReadOnPush 回调函数被调用 参数, request_id: 1, request_info: 110054244927456
正在解析pb数据,pb数据大小: 65817

能否在在初始化的时候加个变量,指明现在是否是调试状态,调试状态下可以正常输出各种信息。非调试状态下就只输出报警或错误信息,上面的类似信息就不需要了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.