按键精灵---调用百度AI进行文字识别脚本

2019-04-15 13:04发布

Import "ShanHai.lua" Import "Cjson.lua" //Dim pic = File.Read("/storage/emulated/0/Pictures/1.jpg") //Dim pic = File.Read("/sdcard/Pictures/1.jpg") //Dim picBase64 = ShanHai.Base64En(pic) Dim picBase64 = ShanHai.ReadFileBase("/sdcard/Pictures/1.jpg") dim picUrlEncode = ShanHai.CharToUrl(picBase64) Dim api_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" //用山海post,得不到结果,不知道为什么,可能是默认的包头不一样 //dim RetJson2 = ShanHai.PostHttp(api_url, "image="&picUrlEncode) dim RetJson = Url.Post(api_url, "image="&picUrlEncode) Dim retTable = Cjson.Decode(RetJson) TracePrint RetJson TracePrint "识别文字行数:" & retTable["words_result_num"] Dim words_results= retTable["words_result"] For i=0 to UBound(words_results) Dim oneUnit = words_results(i) Dim words = oneUnit["words"] TracePrint words Next 不同地址-不同识别能力,一览表(后台地址:https://console.bce.baidu.com/ai/?fromai=1#/ai/ocr/app/detail~appId=665090