'''
Dim dlg As New OpenFileDialog
dlg.MultiSelect = True
dlg.Filter= "图形文件|*.bmp;*.jpg;*.gif,;*.png"
If dlg.ShowDialog = DialogResult.OK Then
Dim txt As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim pic1 As WinForm.PictureBox = e.Form.Controls("PictureBox1")
Dim str As String
For Each fl As String In dlg.FileNames
pic1.ImageFile = fl
Dim kh As String = FileSys.GetName(fl).split(".")(0) '取文件名
try
Dim client As new Baidu.Aip.Ocr.Ocr(Vars("APIKey"), Vars("SecretKey")) '初始化接口类,传入创建的应用的API Key,Secret Key
client.Timeout = 60000 '设置超时时间
Dim data() As Byte = System.IO.File.ReadAllBytes(fl) '把图片文件字节流加载进来,
Dim options As new Dictionary(of String, object) '使用字典传递参数
options.Add("detect_direction","true") '是否检测图像朝向,默认不检测
options.Add("probability","true")
Dim result = client.GeneralBasic(data, options) '调用接口开始识别,返回值为JObject对象
If result("error_code") IsNot Nothing AndAlso result("error_code") <> 0 Then
txt.text = "识别失败: " & vbcrlf & result("error_msg").Tostring
Else
Dim ja As JArray = result("words_result")
For i As Integer = 0 To ja.Count - 1
str = str & vbcrlf & ja(i)("words").Tostring
Next
End If
str = "★★★" & kh & vbcrlf & str '每张图片添加图片名称
catch ex As exception
txt.text = str & vbcrlf & "识别接口调用失败,错误描述: " & vbcrlf & ex.message
End try
Next
txt.text = str
End If
此主题相关图片如下:tt截图未命名.bmp