private Sub QueryOCR
Dim json As JSONGenerator
json.Initialize(CreateMap("data-binary":ConvertImage2Binary(File.DirAssets,"speed.png")))
Dim HttpClient As HttpJob
HttpClient.Initialize("", Me)
HttpClient.PostString(API_URL,json.ToString)
HttpClient.GetRequest.SetContentType("application/json")
HttpClient.GetRequest.SetHeader("Authorization","Bearer "&AcessToken)
Wait For (HttpClient) JobDone(HttpClient As HttpJob)
If HttpClient.Success Then
'The result is a json string. We parse it and log the OCR txt.
Dim jp As JSONParser
jp.Initialize(HttpClient.GetString)
Dim txtRes As List = jp.NextArray
For Each res As Map In txtRes
Log("Speed: " & res.Get("generated_text"))
Next
Else
Log(HttpClient.ErrorMessage)
End If
HttpClient.Release
End Sub
Sub ConvertImage2Binary(Dir As String, FileName As String) As Byte()
Return Bit.InputStreamToBytes(File.OpenInput(Dir, FileName))
End Sub