调用百度api车牌识别本地图片中的号码
By
admin
at 2017-12-29 • 0人收藏 • 1435人看过
感谢xauto和aardio作者一鹤写的baidu的api库
http://bbs.aardio.com/forum.php?mod=viewthread&tid=22093&extra=page%3D1
首先建立库
baidu.aardio文件
import web.rest.jsonLiteClient; namespace baidu; class client{ ctor(apiKey,secretKey){ this = ..web.rest.jsonLiteClient() this.apiKey = apiKey; this.secretKey = secretKey; this.oauthApi = this.api("https://aip.baidubce.com/oauth/2.0/","GET"); }; auth = function(){ var result,err = this.oauthApi.token({ grant_type = "client_credentials"; client_id = this.apiKey; client_secret = this.secretKey; }); if(!result[["access_token"]]) return null,"认证失败"; this.oauthInfo = result; this.extraUrlParameters = { access_token = result.access_token; } return this.oauthInfo; } }
然后主界面上代码如下:
import win.ui; /*DSG{{*/ mainForm = win.form(text="aardio form";right=759;bottom=469;acceptfiles=1) mainForm.add( button={cls="button";text="button";left=31;top=409;right=735;bottom=465;z=1}; edit={cls="edit";left=38;top=15;right=734;bottom=53;edge=1;z=2}; edit2={cls="edit";left=38;top=68;right=734;bottom=392;edge=1;multiline=1;z=3} ) /*}}*/ var filePath; mainForm.wndproc = function(hwnd,message,wParam,lParam){ select( message ) { case 0x233/*_WM_DROPFILES*/{ filePath = win.getDropFile(wParam )[1]; mainForm.edit.text = filePath; } else{ } } } import string.base64; import inet.url; mainForm.button.oncommand = function(id,event){ import baidu; //创建百度客户端 var http = baidu.client( "8FzUXXXXXXXxxxxxxXXXdn89l",//你自己的API Key "GGXLXXXXXXXXXXXXXXXxxxxxXXXXXXXXGxM" //你自己的Secret Key ) //oauth认证 if(! http.auth() ){ error("认证失败") } //车牌识别接口 var ocr = http.api("https://aip.baidubce.com/rest/2.0/ocr/v1/"); //调用ocr var result = ocr.license_plate( image = inet.url.encodeUri(string.base64.encode(string.load(filePath))); ) mainForm.edit2.print(result ,'\r\n' ) } mainForm.enableDpiScaling(); mainForm.show(); return win.loopMessage();
拖拽含有车牌号的图片到窗口, 然后点识别即可. 耐心等待识别完成
2 个回复 | 最后更新于 2017-12-29
登录后方可回帖
如果要识别图片中有好几个车牌号,那么增加一个属性即可.
但,切记两个属性的话用{}括起来才可以.