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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liujiayu2/article/details/84651348
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

猜你喜欢

转载自blog.csdn.net/liujiayu2/article/details/84651348