.NET World - Problema riconoscimento ocr visual basic 2010.net
Cerca
 











Forum - .NET World - Problema riconoscimento ocr visual basic 2010.net

Avatar
pescarese77 (Normal User)
Newbie


Messaggi: 7
Iscritto: 02/02/2012

Pollice su 0 Pollice su 0 (0%)
Segnala al moderatore
Postato alle 16:43
Giovedì, 02/02/2012
volevo realizzare il riconoscimento di carattere per recuperare informazioni da finestra esterna di altro programma ho trovato il seguente codice
Codice sorgente - presumibilmente VB.NET

  1. Imports System.Drawing.Imaging
  2.  
  3. Public Class Form9
  4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  5.         Dim dir As String = Environment.SystemDirectory
  6.         If TextBox1.Text = "" Then
  7.             MsgBox("Please, Pick the desired image first!!!", MsgBoxStyle.Information, "No Image Selected")
  8.         Else
  9.             Try
  10.                 MergeImages(PictureBox1.Image)
  11.                 PictureBox2.Image.Save(dir & "\test.png")
  12.                 fncOCR_Text(dir & "\test.png")
  13.                 System.IO.File.Delete(dir & "\test.png")
  14.             Catch ex As Exception
  15.                 MsgBox("There is something wrong with the image!!!" & vbNewLine & ex.Message, MsgBoxStyle.Exclamation, "ERROR!")
  16.             End Try
  17.  
  18.         End If
  19.  
  20.     End Sub
  21.  
  22.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  23.         Dim openFileDialog1 As New OpenFileDialog()
  24.         openFileDialog1.InitialDirectory = "c:\"
  25.         openFileDialog1.Filter = "Images (*.*)|*.*"
  26.         openFileDialog1.InitialDirectory = Application.StartupPath
  27.         openFileDialog1.ShowDialog()
  28.         TextBox1.Text = openFileDialog1.FileName
  29.         PictureBox1.ImageLocation = (TextBox1.Text)
  30.     End Sub
  31.  
  32.     Public Function MergeImages(ByVal Pic1 As Image) As Image
  33.  
  34.         Dim MergedImage As Image ' This will be the finished merged image
  35.         Dim bm As New Bitmap(150, 60, PixelFormat.Format32bppArgb)
  36.         Dim gr As Graphics = Graphics.FromImage(bm)
  37.         gr.FillRectangle(New SolidBrush(Color.White), New Rectangle(0, 0, 800, 600))
  38.         gr.DrawImage(Pic1, 0, 0)
  39.         MergedImage = bm
  40.         PictureBox2.Image = MergedImage
  41.         gr.Dispose()
  42.         Return MergedImage
  43.     End Function
  44.  
  45.     Public Function fncOCR_Text(ByVal strImagePath As String) As String
  46.  
  47.         'declaring required variables for OCR
  48.         Dim miDoc As MODI.Document
  49.         Dim miLayout As MODI.Layout
  50.         'Dim strLayoutInfo As String
  51.         Dim strText As String
  52.  
  53.         'Recognizing the Document
  54.         miDoc = New MODI.Document
  55.         miDoc.Create(strImagePath)
  56.         miDoc.Images(0).OCR()
  57.  
  58.         'Storing the value in a variable and returning it
  59.         miLayout = miDoc.Images(0).Layout
  60.         strText = Trim(miLayout.Text)
  61.         fncOCR_Text = strText
  62.         TextBox2.Text = strText
  63.  
  64.  
  65.         'Rleasing the Memory
  66.         miLayout = Nothing
  67.         miDoc = Nothing
  68.     End Function
  69.  
  70.     Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
  71.         Dim miDoc As MODI.Document
  72.         Dim miWord As MODI.Word
  73.         Dim strWordInfo As String
  74.  
  75.         ' Load an existing TIFF file.
  76.         miDoc = New MODI.Document
  77.         miDoc.Create("C:\document1.tif")
  78.  
  79.         ' Perform OCR.
  80.         miDoc.Images(0).OCR()
  81.  
  82.         ' Retrieve and display word information.
  83.         miWord = miDoc.Images(0).Layout.Words(2)
  84.         strWordInfo = _
  85.           "Id: " & miWord.Id & vbCrLf & _
  86.           "Line Id: " & miWord.LineId & vbCrLf & _
  87.           "Region Id: " & miWord.RegionId & vbCrLf & _
  88.           "Font Id: " & miWord.FontId & vbCrLf & _
  89.           "Recognition confidence: " & _
  90.           miWord.RecognitionConfidence & vbCrLf & _
  91.           "Text: " & miWord.Text
  92.         MsgBox(strWordInfo, vbInformation + vbOKOnly, _
  93.           "Word Information")
  94.  
  95.         miWord = Nothing
  96.         miDoc = Nothing
  97.  
  98.     End Sub
  99. 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


Fabio
PM
 

Creative Commons License
Il layout di questo sito è concesso sotto licenza Creative Commons.
Per maggiori informazioni sulle licenze dei contenuti del sito, clicca.