0
votes

Have you ever tried to use this code below? Making and OCR using VB.net.

The problem I've encountered is that when i run the program (it runs), the Picturebox was moving to the right and gone. Please do help to fix my problem.

Code:

Imports Emgu.CV
Imports Emgu.Util
Imports Emgu.CV.OCR
Imports Emgu.CV.Structure

Public Class Form1

    Dim OCRz As Tesseract = New Tesseract("tessdata", "eng", Tesseract.OcrEngineMode.OEM_TESSERACT_ON­LY)
    Dim pic As Bitmap = New Bitmap(270, 100)
    Dim gfx As Graphics = Graphics.FromImage(pic)

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'If Windows XP

        gfx.CopyFromScreen(New Point(Me.Location.X + PictureBox1.Location.X + 4, Me.Location.Y + PictureBox1.Location.Y + 30), New Point(0, 0), pic.Size)\

        PictureBox1.Image = pic

        'If Windows 7
        'gfx.CopyFromScreen(MousePositi­on, New Point(0, 0), pic.Size)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OCRz.Recognize(New Image(Of Bgr, Byte)(pic))
        RichTextBox1.Text = OCRz.GetText
    End Sub

End Class
3

3 Answers

3
votes

Add an additional line to the timer1_tick

gfx.CopyFromScreen(New Point(Me.Location.X + PictureBox1.Location.X + 4, Me.Location.Y + PictureBox1.Location.Y + 30), New Point(0, 0), pic.Size)

PictureBox1.Image = pic

PictureBox1.Image = nothing

should solve your problem

0
votes

Try commenting these two lines:

gfx.CopyFromScreen(New Point(Me.Location.X + PictureBox1.Location.X + 4, Me.Location.Y + PictureBox1.Location.Y + 30), New Point(0, 0), pic.Size)
PictureBox1.Image = pic
0
votes

I had the very same problem with the same code.

First off, the offsets in the code line below need to be adjusted to match the specifics of your form. I had to increase 4 to 8 on my code.

gfx.CopyFromScreen(New Point(Me.Location.X + PictureBox1.Location.X + 4, Me.Location.Y + PictureBox1.Location.Y + 30), New Point(0, 0), pic.Size)

I also had an issue (Windows 7, Visual Basic 2010 Express, in that the image would not refresh correctly. After looking, it occurred to me there was no reason for me to actually populate the picture image. Just leave it transparent. After commenting that out, worked like a charm.

Mind you, the OCR is not very good, but the code now does what I wanted it to do.