找回密码
 立即注册

微信登录

只需一步,快速开始

QQ登录

只需一步,快速开始

查看: 24|回复: 0

[分享] TomatoOCR文字识别

[复制链接]
  • TA的每日心情
    开心
    昨天 07:38
  • 签到天数: 52 天

    连续签到: 1 天

    [LV.5]常住居民I

    9

    主题

    56

    回帖

    680

    积分

    高级会员

    积分
    680
    来自: 中国福建泉州
    发表于 昨天 07:48 | 显示全部楼层 |阅读模式 来自: 中国福建泉州
    非业余 - aardio 编程语言 - 非官方问答社区
    风行者三期培训:Aardio+Python+Flutter,1000集课程让你成为全栈开发高手!https://mp.weixin.qq.com/s/_WOoHFtITUyLk2k7BXYGkg
    Aardio培训大揭秘,轻松上手打造个人项目!https://mp.weixin.qq.com/s/cr47qhp_Cpz0p57lbbPwug
    aardio风行者第二期培训班https://mp.weixin.qq.com/s/uB6XHUDnGSk0JlWuiBE9AA
    aardio风行者第三期培训班https://mp.weixin.qq.com/s/cdZcvFiAWhlYTaSrQGCPvA
    aardio调用例子
    https://www.52tomato.com/docs/index.html#/guide/plugin/aardio/windows

    插件下载
    https://www.123684.com/s/NiUnjv-VeRg3

    下载插件后,改名为TomatoOCR.dll,并将dll放入到项目的资源文件中。


    OCR
    以下代码拷贝到代码中,配置license后,点击运行

    [AAuto] 纯文本查看 复制代码
    import win.ui;
    import console;
    /*DSG{{*/
    mainForm = win.form(text="TmoTestDemo";right=757;bottom=467)
    mainForm.add(
    button={cls="button";text="Button";left=144;top=136;right=257;bottom=181;z=1}
    )
    /*}}*/
    
    mainForm.button.oncommand = function(id,event){
        // 加载插件
        var tmo = raw.loadDll($"\res\TomatoOCR.dll");
        
        init = tmo.api("init", "void(int)", "cdecl");
        setHttpIntervalTime = tmo.api("setHttpIntervalTime", "void(int)", "cdecl");
        setMode = tmo.api("setMode", "void(s)", "cdecl");
        setLicense = tmo.api("setLicense", "s(s,s)", "cdecl");
        
        lock = tmo.api("lock", "int()", "cdecl");
        setRecType = tmo.api("setRecType", "void(int, s)", "cdecl");
        setDetBoxType = tmo.api("setDetBoxType", "void(int, s)", "cdecl");
         setDetUnclipRatio = tmo.api("setDetUnclipRatio", "void(int, float)", "cdecl");
         setRecScoreThreshold = tmo.api("setRecScoreThreshold", "void(int, float)", "cdecl");
        setReturnType = tmo.api("setReturnType", "void(int, s)", "cdecl");
        setBinaryThresh = tmo.api("setBinaryThresh", "void(int, int)", "cdecl");
        setRunMode = tmo.api("setRunMode", "void(int, s)", "cdecl");
        setFilterColor = tmo.api("setFilterColor", "void(int, s)", "cdecl");
        setFilterColorPath = tmo.api("setFilterColorPath", "void(int, s)", "cdecl");
    
        ocrFile = tmo.api("ocrFile", "s(int,s,int)", "cdecl");
        ocrScreen = tmo.api("ocrScreen", "s(int, int,int,int,int,int,s)", "cdecl");
        ocrDMImageData = tmo.api("ocrDMImageData", "s(int, s,int)", "cdecl");
        ocrBase64 = tmo.api("ocrBase64", "s(int, s,int)", "cdecl");
        
        findTapPoint = tmo.api("findTapPoint", "s(int, s)", "cdecl");
        findTapPoints = tmo.api("findTapPoints", "s(int, s)", "cdecl");
        
        unlock = tmo.api("unlock", "void(int)", "cdecl");
        
        
        init(2) // 初始化两个线程
        
        _license = "" // 设置license,见授权码获取
        _remark = "测试"
        setLicense(_license, _remark))
        
        // ----------------------注:以上代码全局只需写一次-------------------------------
        
        obj = lock()  // 获取句柄,与unlock一一对应,必写
        
        setRecType(obj, "ch-3.0");
        // 注:ch、ch-2.0、ch-3.0版可切换使用,对部分场景可适当调整
        // "ch":普通中英文识别,1.0版模型
        // "ch-2.0":普通中英文识别,2.0版模型
        // "ch-3.0":普通中英文识别,3.0版模型
        // "number":数字识别
        // "cht":繁体,"japan":日语,"korean":韩语
         
         setDetScaleRatio(obj, 1.0)  // 设置输入图片缩放大小的参数 - 默认为1.0。值范围0.1-10.0之间
        
        setDetBoxType(obj, "rect");
        // 调整检测模型检测文本参数- 默认"rect": 由于手机上截图文本均为矩形文本,从该版本之后均改为rect,"quad":可准确检测倾斜文本
    
        setDetUnclipRatio(obj, 1.9);
        // 调整检测模型检测文本参数 - 默认1.9: 值范围1.6-2.5之间
        
        setRecScoreThreshold(obj, 0.1);
        // 识别得分过滤 - 默认0.1,值范围0.1-0.9之间
             
        setReturnType(obj, "json");
        // 返回类型 - 默认"json": 包含得分、坐标和文字;
        // "text":纯文字;
        // "num":纯数字;
        // 自定义输入想要返回的文本:".¥1234567890",仅只返回这些内容
         
        setBinaryThresh(obj, 0);
        // 二值化设定,非必须
        
        setRunMode(obj, "slow")
        
        //setFilterColor(obj, "", "black"); //  设置滤色值和背景色(black\white),滤色值默认是空的,详细使用见方法说明
          
        
        _type = 3
        // _type=-1 : 检测 + 方向分类 + 识别
        // _type=0 : 只检测
        // _type=1 : 方向分类 + 识别
        // _type=2 : 只识别
        // _type=3 : 检测 + 识别
        // 只检测文字位置:_type=0
        // 全屏识别: _type=3或者不传_type
        // 截取单行文字识别:_type=1或者_type=2
        
        // 例子一,直接按路径去识别图片
        result1 = ocrFile(obj, "D:\\WorkSpaceProjects\\PycharmProjects\\TestLoadTomato\\test_dll\\images\\03.bmp", _type)
        console.log(result1)
        
        // 例子二,传入截图区域
        result2 = ocrScreen(obj, 10, 20, 100, 200, _type, "") // 最后一个参数,默认传“”空字符串,保存的是截图路径
        console.log(result2)
        
        // 例子三,传入图片base64
        result3 = ocrBase64(obj, 图片bease64字符串, _type)  
        console.log(result3)
        
        // 例子四,传入大漠截图对象 char *
        result4 = ocrDMImageData(obj, 大漠截图对象, _type) 
        console.log(result4)
        
        // 找字返回中心点,找不到返回“”空字符串
        point = findTapPoint(obj, "队")
        console.log(point)
        
        // 找字返回所有相匹配的中心点坐标,找不到返回“”空字符串
        points = findTapPoints(obj, "队")
        console.log(points)
        
        unlock(obj)  // 释放句柄
    }
    
    mainForm.show();
    return win.loopMessage();


    运行结果


    YOLO
    注意:目前测试 v5、v8和v11 能正常使用,其他版本如不能使用,请联系客服。 以下代码拷贝到代码中,配置license后,点击运行

    [AAuto] 纯文本查看 复制代码
    import win.ui;
    import console;
    /*DSG{{*/
    mainForm = win.form(text="TmoTestDemo";right=757;bottom=467)
    mainForm.add(
    button={cls="button";text="Button";left=144;top=136;right=257;bottom=181;z=1}
    )
    /*}}*/
    
    mainForm.button.oncommand = function(id,event){
        // 加载插件
        var tmo = raw.loadDll($"\res\TomatoOCR.dll");
        
        init = tmo.api("init", "void(int)", "cdecl");
        setHttpIntervalTime = tmo.api("setHttpIntervalTime", "void(int)", "cdecl");
        setMode = tmo.api("setMode", "void(s)", "cdecl");
        setLicense = tmo.api("setLicense", "s(s,s)", "cdecl");
        
        initYolo = tmo.api("setLicense", "void(s,s,s,s)", "cdecl");
        
        lock = tmo.api("lock", "int()", "cdecl");
        setRecType = tmo.api("setRecType", "void(int, s)", "cdecl");
        setDetBoxType = tmo.api("setDetBoxType", "void(int, s)", "cdecl");
         setDetScaleRatio = tmo.api("setDetScaleRatio", "void(int, float)", "cdecl");
         setDetUnclipRatio = tmo.api("setDetUnclipRatio", "void(int, float)", "cdecl");
         setRecScoreThreshold = tmo.api("setRecScoreThreshold", "void(int, float)", "cdecl");
        setReturnType = tmo.api("setReturnType", "void(int, s)", "cdecl");
        setBinaryThresh = tmo.api("setBinaryThresh", "void(int, int)", "cdecl");
        setRunMode = tmo.api("setRunMode", "void(int, s)", "cdecl");
        setFilterColor = tmo.api("setFilterColor", "void(int, s)", "cdecl");
        setFilterColorPath = tmo.api("setFilterColorPath", "void(int, s)", "cdecl");
    
        ocrFile = tmo.api("ocrFile", "s(int,s,int)", "cdecl");
        ocrScreen = tmo.api("ocrScreen", "s(int, int,int,int,int,int,s)", "cdecl");
        ocrDMImageData = tmo.api("ocrDMImageData", "s(int, s,int)", "cdecl");
        ocrBase64 = tmo.api("ocrBase64", "s(int, s,int)", "cdecl");
        
        findTapPoint = tmo.api("findTapPoint", "s(int, s)", "cdecl");
        findTapPoints = tmo.api("findTapPoints", "s(int, s)", "cdecl");
        
        yoloFile = tmo.api("ocrFile", "s(int,s,s,int,float,float)", "cdecl");
        yoloScreen = tmo.api("ocrScreen", "s(int,s,int,int,int,int,int,float,float,s)", "cdecl");
        yoloDMImageData = tmo.api("ocrDMImageData", "s(int,s,s,int,float,float)", "cdecl");
        yoloBase64 = tmo.api("ocrBase64", "s(int,s,s,int,float,float)", "cdecl");
        
        unlock = tmo.api("unlock", "void(int)", "cdecl");
        
        
        init(2) // 初始化两个线程
        
        _license = "" // 设置license,见授权码获取
        _remark = "测试" // 备注
        setLicense(_license, _remark))
        
        // yolo初始化
        _key = "yolo1"    // 可以同时初始化多个,这里通过key进行区分
        _yolo_secret = ""      // yolo模型解密密钥
        _yolo_model_path = ""  // yolo模型路径,必传
        _yolo_label_path = ""  // yolo标签路径,可不传,不传返回的是分类编号
        initYolo(_key, _yolo_model_path, _yolo_label_path)
        // ----------------------注:以上代码全局只需写一次-------------------------------
        
        obj = lock()  // 获取句柄,与unlock一一对应,必写
        
        _yolo_key = "yolo1"
        _size = 640          // 图片输入大小
        _score_thresh = 0.35 // 置信度阈值,默认0.35
        _nms_thresh = 0.45   // 非极大值抑制阈值,默认0.45
        
        // 例子一,直接按路径去识别图片
        result1 = yoloFile(obj, _yolo_key, "D:\\WorkSpaceProjects\\PycharmProjects\\TestLoadTomato\\test_dll\\images\\03.bmp", _size, _score_thresh, _nms_thresh)
        console.log(result1)
        
        // 例子二,传入截图区域
        result2 = yoloScreen(obj, _yolo_key, 10, 20, 100, 200, _size, _score_thresh, _nms_thresh, "") // 最后一个参数,默认传“”空字符串,保存的是截图路径
        console.log(result2)
        
        // 例子三,传入图片base64
        result3 = yoloBase64(obj, _yolo_key, 图片bease64字符串, _size, _score_thresh, _nms_thresh)  
        console.log(result3)
        
        // 例子四,传入大漠截图对象 char *
        result4 = yoloDMImageData(obj, _yolo_key, 大漠截图对象, _size, _score_thresh, _nms_thresh) 
        console.log(result4)
        
        
        unlock(obj)  // 释放句柄
    }
    
    mainForm.show();
    return win.loopMessage();


    *官网
    https://www.52tomato.com/
    *文档地址
    https://www.52tomato.com/docs/index.html#/
    *下载地址
    https://www.52tomato.com/docs/index.html#/download
    *博客主页地址
    https://blog.csdn.net/YY007H?type=blog

    支持平台:
    1、插件版平台分:android,ios,windows,分别有如下
    android平台:懒人精灵、easy click、触动精灵、aiwork、autojs及变种(autoxjs)、自动化编辑器、按键精灵、AScript、cheese、云控、冰狐;

    ios平台:按键精灵、触动精灵、触摸精灵、XXTouch、TrollAutoScript;

    windows平台:TC、aardio、易语言、按键精灵。

    2、依赖版平台分:ios,windows,其他平台待定,支持的语言如下:
    windows:c++,c#,go,python等


    非业余 - aardio 编程语言 - 非官方问答社区
    风行者三期培训:Aardio+Python+Flutter,1000集课程让你成为全栈开发高手!https://mp.weixin.qq.com/s/_WOoHFtITUyLk2k7BXYGkg
    Aardio培训大揭秘,轻松上手打造个人项目!https://mp.weixin.qq.com/s/cr47qhp_Cpz0p57lbbPwug
    aardio风行者第二期培训班https://mp.weixin.qq.com/s/uB6XHUDnGSk0JlWuiBE9AA
    aardio风行者第三期培训班https://mp.weixin.qq.com/s/cdZcvFiAWhlYTaSrQGCPvA
    回复

    使用道具 举报

    *滑块验证:
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|非业余 - aardio 编程语言 - 非官方问答社区 知道创宇云防御

    GMT+8, 2025-11-19 07:33 , Processed in 0.138242 second(s), 31 queries .

    Powered by Discuz! X3.5

    © 2001-2025 Discuz! Team.

    快速回复 返回顶部 返回列表