|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
liucqa老师:
您好!
好像跟字库没关系,图片预处理后,我用SavePicture保存成*.jpg会报错“Ocr出错”,但用画图另存就能识别了,或者用ActiveSheet.Pictures.Insert、Chart.Export之后也能识别。我找了一个PNG格式的图片试了一下也会报“Ocr出错”,我把代码贴上,麻烦帮我看一下吧,太感谢了!
- Sub main123()
- For i = 1 To 1
- Dim url$, tt$, cookie$, str() As String
- url = "https://supplier.rt-mart.com.cn/php/checkstr.php"
- Dim ayrHttpBody() As Byte, localFilename As String
- localFilename = "F:\MyImg"
- With CreateObject("WinHttp.WinHttpRequest.5.1") 'Microsoft.XMLHTTP")
- .Open "GET", url, True
- ' .SetRequestHeader "Cookie", cookie
- .Send
- .WaitForResponse
- If .Status = 200 Then
- ayrHttpBody() = .ResponseBody
- Open localFilename For Binary As #1
- Put #1, , ayrHttpBody()
- Close #1
- Else
- MsgBox "验证码下载失败"
- End If
- End With
-
- ActiveSheet.Pictures.Insert (localFilename) '插入图片
- Kill localFilename
- localFilename = "F:\MyPicture"
- For Each p In ActiveSheet.Shapes
- p.CopyPicture
- With ActiveSheet.ChartObjects.Add(0, 0, p.Width, p.Height).Chart
- .Paste
- .Export localFilename, "JPG" '导出jpg图片
- .Parent.Delete
- End With
- p.Delete
- Next
- Dim pic As image
- Set pic = New image
- pic.Picture = LoadPicture(localFilename)
- Kill localFilename
- pic.Picture = Convert(pic.Picture, qubiankuang)
- pic.Picture = Convert(pic.Picture, GrayScale)
- pic.Picture = Convert(pic.Picture, BlackWhite, 50)
- pic.Picture = Convert(pic.Picture, quzaodian)
- localFilename = "D:\TTTT\Myjpg" & i & ".jpg"
- stdole.SavePicture pic.Picture, localFilename
- Set pic = Nothing
- ActiveSheet.Pictures.Insert (localFilename) '插入图片
- Kill localFilename
- For Each p In ActiveSheet.Shapes
- p.CopyPicture
- With ActiveSheet.ChartObjects.Add(0, 0, p.Width - 1, p.Height - 1).Chart
- .Paste
- .Export localFilename, "JPG" '导出jpg图片
- .Parent.Delete
- End With
- p.Delete
- Next
- Dim FMyFuns As Object
- Dim MyStr As String
- Set FMyFuns = CreateObject("MyOcrServer.MyOcrServerCom")
- MyStr = FMyFuns.TsOcr("D:\TTTT\Myjpg" & i & ".jpg", "", "", "", "chi_sim")
- MsgBox MyStr
- Set FMyFuns = Nothing
- Next
-
- End Sub
复制代码 |
|