利用管道process.popen调用离线版PaddleOCR-json实现文字识别
By
admin
at 2022-04-21 • 1人收藏 • 1644人看过
之前发过调用在线api版本, 这里测试离线版利用管道功能来调用识别.
PaddleOCR官方:
https://gitee.com/paddlepaddle/PaddleOCR
编译了的paddleOCR-json版本地址:
https://github.com/hiroi-sora/PaddleOCR-json
到json那里下载整个文件解压, 然后将下面的代码写到aardio中, 保存此文件到解压后的根目录里, 然后运行即可.
图片离线OCR文字识别程序。管道输入图片路径,输出识别结果json字符串
更新:
调用 mouse.screenArea 增加了截图识别

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=747;bottom=302)
winform.add(
button={cls="button";text="截图识别";left=3;top=269;right=161;bottom=299;db=1;dl=1;z=2};
button2={cls="button";text="图片识别";left=165;top=269;right=326;bottom=299;db=1;dl=1;z=3};
edit={cls="edit";text="拖动图片到文本框内自动识别!";left=327;top=0;right=748;bottom=299;autohscroll=false;db=1;dl=0.44;dr=1;dt=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=1};
picturebox={cls="picturebox";left=0;top=0;right=329;bottom=267;db=1;dl=1;dr=0.56;dt=1;z=4}
)
/*}}*/
import fsys;
import fsys.dlg;
var OCRFunc = function(path){
path = io.fullpath(path);
thread.invoke(
function(winform,path){
import process.popen;
import web.json;
winform.picturebox.image = path;
winform.edit.text = "";
winform.edit.log( "正在识别,请稍后...",'\r\n' ) ;
var prcs = process.popen("\PaddleOCR_json.exe");
prcs.codepage=936;
prcs.read();//读掉第一行
prcs.write(path++'\n');
prcs.codepage=65001;
var retstr = prcs.read();
//去掉结尾的那个"\r"字符
retstr = string.replace( retstr, "\r*?$", "");
//json解析为table
var tab = web.json.tryParse(retstr);
if(tab){
winform.edit.text = "";
//识别到文字(100)
if(tab.code == 100){
for(i=1;#tab.data;1){
winform.edit.log( tab.data[i].text,'\r\n' ) ;
}
}elseif(tab.code == 101){
//未识别到文字(101)
winform.edit.log( "未识别到文字",'\r\n' ) ;
}else {
//加载图片错误(200)
winform.edit.log( "加载图片错误",'\r\n' ) ;
}
}
prcs.close();
},winform,path
)
}
winform.button.oncommand = function(id,event){
winform.show(false);
win.delay(100);
import mouse.screenArea;
var screenArea = mouse.screenArea(winform);
screenArea.onSelectionChanged = function(rc){
import gdip.snap;
var bmp = gdip.snap(screenArea.hwnd,rc.xywh());
if(io.exist("/TempPic.jpg")) io.remove("/TempPic.jpg");
win.delay(100);
bmp.save("/TempPic.jpg",100);
owner.close();
winform.show();
win.setTimeout(
function(){
OCRFunc("/TempPic.jpg");
},5
)
}
screenArea.doModal();
}
winform.onDropFiles = function(files){
if(#files){
var path = files[1];
OCRFunc(path);
}
}
winform.button2.oncommand = function(id,event){
var path = fsys.dlg.open("图片文件|*.jpg;*.bmp");
if(path){
OCRFunc(path);
}
}
winform.show();
win.loopMessage();完整下载地址:
链接:https://pan.baidu.com/s/17ap1NOqPS0wFa3RaoYekFA
提取码:ttmn
3 个回复 | 最后更新于 2022-04-22
登录后方可回帖

更新:
调用 mouse.screenArea 增加了截图识别