Detecting Text in an image

Priyank Thakkar picture Priyank Thakkar · Jun 30, 2012 · Viewed 11k times · Source

I am using AForge.NET library for image processing. Using this library I am able detect basic shapes within an image. How can I detect the text within an image using the AForge.NET library?

Answer

SuperPrograman picture SuperPrograman · Jun 30, 2012

You will need to use Optical Character Recognition (OCR). One link I found on using it with AForge can be visited here. Some code from the link:

// "K" letter, but a little bit noised
float[] pattern = new float [] {
        0.5f, -0.5f, -0.5f,  0.5f,  0.5f,
        0.5f, -0.5f,  0.5f, -0.5f,  0.5f,
        0.5f,  0.5f, -0.5f, -0.5f, -0.5f,
        0.5f, -0.5f,  0.5f, -0.5f, -0.5f,
        0.5f, -0.5f, -0.5f,  0.5f, -0.5f,
        0.3f, -0.5f, -0.5f,  0.5f,  0.5f};

// get network's output
float[] output = neuralNet.Compute(pattern);

int i, n, maxIndex = 0;

// find the maximum from output
float max = output[0];
for (i = 1, n = output.Length; i < n; i++)
{
    if (output[i] > max)
    {
        max = output1[i];
        maxIndex = i;
    }
}

//
System.Diagnostics.Debug.WriteLine(
  "network thinks it is - " + (char)((int) 'A' + maxIndex));

The only other way I can think of doing it, is using Tessaract-OCR which can read a wide variety of image formats and convert them to text in over 40 languages. There are also many other ways of doing it out there, including using Microsoft Office, or Emgu cv.

There's one more link which might work. It detects playing cards in AForge, and while doing so reads the numbers or J, Q, and K in the corner. You may have seen it already.