Intro
 

OCRing an image is a simple process. First you create an ABCocr Ocr object and you assign it an image. When it has finished processing the image you look at the results.

 

   

Code
 

First we create an ABCocr Ocr object and assign it an image that we want to OCR.

[C#]
Bitmap bitmap = (Bitmap)Bitmap.FromFile(inPath);
Ocr ocr = new Ocr();
ocr.SetBitmap(bitmap);

[Visual Basic]
Dim bm As Bitmap = DirectCast(Bitmap.FromFile(inPath), Bitmap)
Dim ocr As New Ocr()
ocr.SetBitmap(bm)

 

   

Code
 

We iterate through all the words that ABCocr has found. We then draw a rectangle round each word in the image and draw our extracted text in a different color. Finally we save the image.

[C#]
using (Graphics graphics = Graphics.FromImage(bitmap)) {
  graphics.PageUnit = GraphicsUnit.Pixel;
  foreach (Word word in ocr.Page.Words) {
    Font font = new System.Drawing.Font("Arial", word.Bounds.Height, FontStyle.Regular, GraphicsUnit.Pixel);
    TextFormatFlags flags = TextFormatFlags.NoClipping | TextFormatFlags.NoPadding;
    TextRenderer.DrawText(graphics, word.Text, font, word.Bounds, Color.Red, flags);
    graphics.DrawRectangle(Pens.Green, word.Bounds);
  }
}
bitmap.Save(outPath);

[Visual Basic]
Using gr As Graphics = Graphics.FromImage(bm)
  gr.PageUnit = GraphicsUnit.Pixel
  For Each word As Word In ocr.Page.Words
    Dim flags As TextFormatFlags = TextFormatFlags.NoClipping Or TextFormatFlags.NoPadding
    TextRenderer.DrawText(gr, word.Text, font, word.Bounds, Color.Red, flags)
    gr.DrawRectangle(Pens.Green, word.Bounds)
  Next
End Using
bm.Save(outPath)

 

   

Results
 


1-report.png


output.png