02/02/12 15:43
pescarese77
volevo realizzare il riconoscimento di carattere per recuperare informazioni da finestra esterna di altro programma ho trovato il seguente codice
non mi funziona vorrei sapere se può dipendere dalla grandezza dell'immagine che ho visto che la prendo con il cattura schermo grazie mille
Imports System.Drawing.Imaging Public Class Form9 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dir As String = Environment.SystemDirectory If TextBox1.Text = "" Then MsgBox("Please, Pick the desired image first!!!", MsgBoxStyle.Information, "No Image Selected") Else Try MergeImages(PictureBox1.Image) PictureBox2.Image.Save(dir & "\test.png") fncOCR_Text(dir & "\test.png") System.IO.File.Delete(dir & "\test.png") Catch ex As Exception MsgBox("There is something wrong with the image!!!" & vbNewLine & ex.Message, MsgBoxStyle.Exclamation, "ERROR!") End Try End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.InitialDirectory = "c:\" openFileDialog1.Filter = "Images (*.*)|*.*" openFileDialog1.InitialDirectory = Application.StartupPath openFileDialog1.ShowDialog() TextBox1.Text = openFileDialog1.FileName PictureBox1.ImageLocation = (TextBox1.Text) End Sub Public Function MergeImages(ByVal Pic1 As Image) As Image Dim MergedImage As Image ' This will be the finished merged image Dim bm As New Bitmap(150, 60, PixelFormat.Format32bppArgb) Dim gr As Graphics = Graphics.FromImage(bm) gr.FillRectangle(New SolidBrush(Color.White), New Rectangle(0, 0, 800, 600)) gr.DrawImage(Pic1, 0, 0) MergedImage = bm PictureBox2.Image = MergedImage gr.Dispose() Return MergedImage End Function Public Function fncOCR_Text(ByVal strImagePath As String) As String 'declaring required variables for OCR Dim miDoc As MODI.Document Dim miLayout As MODI.Layout 'Dim strLayoutInfo As String Dim strText As String 'Recognizing the Document miDoc = New MODI.Document miDoc.Create(strImagePath) miDoc.Images(0).OCR() 'Storing the value in a variable and returning it miLayout = miDoc.Images(0).Layout strText = Trim(miLayout.Text) fncOCR_Text = strText TextBox2.Text = strText 'Rleasing the Memory miLayout = Nothing miDoc = Nothing End Function Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click Dim miDoc As MODI.Document Dim miWord As MODI.Word Dim strWordInfo As String ' Load an existing TIFF file. miDoc = New MODI.Document miDoc.Create("C:\document1.tif") ' Perform OCR. miDoc.Images(0).OCR() ' Retrieve and display word information. miWord = miDoc.Images(0).Layout.Words(2) strWordInfo = _ "Id: " & miWord.Id & vbCrLf & _ "Line Id: " & miWord.LineId & vbCrLf & _ "Region Id: " & miWord.RegionId & vbCrLf & _ "Font Id: " & miWord.FontId & vbCrLf & _ "Recognition confidence: " & _ miWord.RecognitionConfidence & vbCrLf & _ "Text: " & miWord.Text MsgBox(strWordInfo, vbInformation + vbOKOnly, _ "Word Information") miWord = Nothing miDoc = Nothing End Sub End Class
non mi funziona vorrei sapere se può dipendere dalla grandezza dell'immagine che ho visto che la prendo con il cattura schermo grazie mille
aaa