ocr范例识别文字保留原格式输出

By the100s at 2021-12-06 • 0人收藏 • 1469人看过

//代码来自.\aardio\codes\范例程序\I) 自动化\1) 找图找色找字\ocrLite.aardio

//原理:使用html的svg <text x="1" y="2">文字</text>来实现.

//期待能复制文本保留原格式,但是没办法了,技不如大佬们.

//屏幕找字完整版
import win.ui;
/*DSG{{*/
var winform = win.form(text="string.ocrLite简单演示";right=796;bottom=504)
winform.add(
button={cls="button";text="识别剪贴板图像";left=528;top=423;right=712;bottom=477;db=1;dr=1;z=2};
edit={cls="edit";left=497;top=36;right=764;bottom=403;db=1;dr=1;dt=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=3};
plus={cls="plus";left=25;top=36;right=474;bottom=403;db=1;dl=1;dr=1;dt=1;repeat="scale";z=1}
)
/*}}*/

/*DSG{{*/
var winform2 = win.form(text="输出窗口";right=1151;bottom=745;parent=...;scroll=1)
winform.add()
/*}}*/

//web.form 使用系统自带的 IE 内核,生成的EXE体积很小,
//即使 WIN10 删除IE浏览器,IE内核浏览器控件仍作为操作系统组件被保留。
//大家通常低估了IE控件的作用:IE11已普及,一般用不到最新前端技术的话IE控件是非常强大的。
import web.form;
var wb = web.form.ie11( winform2);//低于IE11就自动安装IE11

//相关 OCR 范例:"~\codes\范例程序\2) 调用其他语言\2) dotNet\ocr.aardio"
import string.ocrLite;
import string.ocrLite.defaultModels;
import win.clip;

var ocr = string.ocrLite(,true);
winform.button.oncommand = function(id,event){
var hBmp = win.clip.readBitmap()
if(!hBmp){
winform.edit.print("剪贴板未读取到图像")
return;
}

var bmp = gdip.bitmap(hBmp);
var ocrRet = ocr.detectBitmap(bmp);
if(ocrRet){
winform.plus.background = ocrRet.resultBitmap;

winform.edit.text = ocrRet.text;
winform.edit.text = "";

import web.json;
// import console;
var hh=`<html>
<head>
<style>
html,body {
width: 100%;
height: 100%;
margin: 0;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg"
width="1024px" height="1024px" viewBox="0 0 1024 1024" style="background-color: yellow"><text>`

var hf=`
</text></svg>
</body>
</html>
`  
all=""
str=""
for i,block in table.eachIndex(ocrRet.blocks){
winform.edit.print(block.text);
//console.dump(block.points[1]["x"])
str=str + "<tspan x='" +block.points[1]["x"]+"' y='"+block.points[1]["y"]+"'>" + block.text +"</tspan>" +'\n\r'

winform.edit.print(web.json.stringify(block.points,false));
}
all=hh++ str ++hf
//console.dump(all)
wb.html=all
winform2.show();
}
}


winform.show();

//请使用 string.ocrLite扩展库 以及 aardio 最新版
var ocrResult = ocr.detectClient(winform.hwnd);
if(ocrResult){  


//也可以更简单一些下面这样写
ocrResult.click("识别剪贴板图像",0.1);
}

win.loopMessage();

运行效果如下图:

QQ图片20211206221318.png

7 个回复 | 最后更新于 2021-12-20
2021-12-07   #1

可以考虑用word,识别的一个区域信息对应word文本框位置和内容

2021-12-07   #2

保留什么样的格式,要干什么?这很重要…

2021-12-07   #3

回复#2 @nlysh007 :

像abbyy保留格式的识别效果

2021-12-08   #4

想到一个方法:设置一个xy波动范围,排序x,y坐标,x相当于文本行,y相当于文本列,根据排序结果组合文字

2021-12-08   #5

abbyy识别率还是太低

2021-12-10   #6

回复#5 @the100s :

abbyy的可扩展性太差,如果结合常见中文分词,进行识别后自动校正要好的多

2021-12-20   #7

回复#6 @popy32 :

是我误会abbyy了,识别率不低,OCR的天花板级别

登录后方可回帖

登 录
信息栏
 私人小站

本站域名

ChengXu.XYZ

投诉联系:  popdes@126.com



快速上位机开发学习,本站主要记录了学习过程中遇到的问题和解决办法及上位机代码分享

这里主要专注于学习交流和经验分享.
纯私人站,当笔记本用的,学到哪写到哪.
如果侵权,联系 Popdes@126.com

友情链接
Aardio官方
Aardio资源网


才仁机械


网站地图SiteMap

Loading...