调用百度OCR识别剪切板内图像
By
admin
at 2019-05-23 • 0人收藏 • 2029人看过
import win.ui; /*DSG{{*/ var winform = win.form(text="百度API测试";right=747;bottom=698;acceptfiles=1) winform.add( button={cls="button";text="识别";left=596;top=411;right=731;bottom=449;dr=1;dt=1;z=3}; edit={cls="edit";left=16;top=18;right=731;bottom=379;db=1;dl=1;dr=1;dt=1;edge=1;multiline=1;vscroll=1;z=1}; editUrl={cls="edit";text="http://bbs.aardio.com/data/attachment/forum/201712/29/213348g7wpsalpnn8gdnnp.png.thumb.jpg";left=16;top=415;right=591;bottom=447;align="right";dl=1;dr=1;dt=1;edge=1;z=2}; picturebox={cls="picturebox";left=46;top=472;right=421;bottom=661;z=5}; static={cls="static";text="请输入图像文件路径、或者网址:";left=21;top=392;right=234;bottom=407;dr=1;dt=1;transparent=1;z=4} ) /*}}*/ import web.json; winform.button.oncommand = function(id,event){ winform.button.disabled = true; thread.invoke( function(winform){ import win.clip; import baidu.client; import win.ui; import console; var http = baidu.client();//创建百度客户端 //oauth认证 if(! http.setAuth( //可以用一个参数直接写access_token,或者写一个可以获取access_token的网址 "tTSWGGGaLXz48TWAN9g1qgGk",//你自己的API Key "ha10bCHkw2UssZDrbo09snvXw2x4SZeb" //你自己的Secret Key ) ){ winform.edit.print("oauth认证证失败") } else{ //OCR识别接口 var ocr = http.api("https://aip.baidubce.com/rest/2.0/ocr/v1/"); hBmp = win.clip.readBitmap(); winform.picturebox.setImage(hBmp); //调用ocr var result = ocr.general_basic( //这里可以写直接写本地图片路径、或者加载后的图像数据、也可以写URL //image = winform.picturebox.image image = gdip.bitmap(hBmp).saveToBuffer(); ) if(result) winform.edit.print(result); else { winform.edit.print( http.lastResponse() ); } } winform.button.disabled = false; },winform ) } winform.onDropFiles = function(files){ winform.editUrl.text = files[1]; } winform.show() win.loopMessage();
代码来自 aar群 圣地 提供,感谢分享
登录后方可回帖