2 yuanjiansh yuanjiansh 于 2016.09.17 16:17 提问

vb studio 2013 tesseract ocr 后图片不释放,第二次存图失败 50C

‘使用OCR后图片一直被占用,导致后面无法更新图片

Public Class Form1
'使用Tesseract進行OCR
Function TesseractOCR(img As Bitmap) As String
Try
Dim ocr As New tessnet2.Tesseract
ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
ocr.Init(".\tessdata", "eng", False)
Dim result As List(Of tessnet2.Word) = ocr.DoOCR(img, Rectangle.Empty)
Dim str As String = ""
For i As Integer = 0 To result.Count - 1
str &= result(i).Text
Next
Return str
img = Nothing
Catch ex As Exception
Throw ex
End Try
Return String.Empty
End Function

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
     Dim img As New Bitmap(Image.FromFile("D:\newtest2.bmp"))
     TextBox1.Text = TesseractOCR(img)
 End Sub

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
     Dim SngPer As Integer
     SngPer = CInt(TextBox2.Text)
     Dim PicOld As Image = Image.FromFile("D:\test2.bmp")
     Dim PicNew As New System.Drawing.Bitmap(PicOld, PicOld.Width * SngPer, PicOld.Height * SngPer)
     PicNew.Save("D:\newtest2.bmp", Drawing.Imaging.ImageFormat.Bmp)
 End Sub

End Class

下载地址:http://pan.baidu.com/s/1nvo6N7j

1个回答

zqbnqsdsmd
zqbnqsdsmd   2016.09.28 01:24
Csdn user default icon
上传中...
上传图片
插入图片