OCR generally works by trying to recognize black text characters on white background, so most OCR approaches try to “binarize” the image and convert it to black and white.
Considering the image you are using, there are a number of issues here that make this difficult:
- The grey background has shades close to the pencil writing and the line.
- The penciled characters are not made of solid shapes have many shades in them.
- The dotted line and the characters have close shades of color.
It is a combination of these problems that leads to either no text being recognized, as the text does not stand out enough, or large amount of false text being detected as the OCR tries to interpret the dotted line and the background.
This means that, for this type of image, some image processing will be needed to make the text more detectable for OCR.
For this particular image, for example, I was able to use image processing classes from the LEADTOOLS toolkit to achieve the result below. (Disclaimer: I am an employee of the vendor of this toolkit)
The image processing used was as follows:
- Histogram Equalization to bring out the details in the dark characters of the text.
- Intensity detection and binary segmentation along a wide range of pixel values to filter out the noise in the image.
- Noise reduction through along a median of pixel color values to remove the dotted line but keeping the text as clear as possible.
Noise reduction through along a median of pixel color values to remove the dotted line but keeping the text as clear as possible.
The code for this looks like the following:
HistogramEqualizeCommand histCommand = new HistogramEqualizeCommand();
histCommand.Run(image);
IntensityDetectCommand intensityDetectCommand = new IntensityDetectCommand();
intensityDetectCommand.LowThreshold = 5;
intensityDetectCommand.HighThreshold = 255;
intensityDetectCommand.Run(image);
MedianCommand medCommand = new MedianCommand();
medCommand.Dimension = 9;
medCommand.Run(image);
Then by using OCR/ICR classes from the toolkit I was able to recognize the text:
ICR was required to recognize the text. Please note that this is not available on the Java version of the toolkit.
Alternatively, if you do not want to perform image processing, consider changing the base image:
- Use black text on a white background.
- Use ink to write solid text character instead of pencil.
- Hand-print the characters to make them stand out more.
- Use solid faint lines instead of dotted lines.