Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Library for image recognition: images containing words to string

Does anyone know of a c++ library for taking an image and performing image recognition on it such that it can find letters based on a given font and/or font height? Even one that doesn't let you select a font would be nice (eg: readLetters(Image image).

like image 422
Zombies Avatar asked Jan 20 '09 19:01

Zombies


2 Answers

While I cannot recommend one in particular, the term you are looking for is OCR (Optical Character Recognition).

like image 45
Sparr Avatar answered Oct 21 '22 03:10

Sparr


I've been looking into this a lot lately. Your best is simply Tesseract. If you need layout analysis on top of the OCR than go with Ocropus (which in turn uses Tesseract to do the OCR). Layout analysis refers to being able to detect position of text on the image and do things like line segmentation, block segmentation, etc.

I've found some really good tips through experimentation with Tesseract that are worth sharing. Basically I had to do a lot of preprocessing for the image.

  1. Upsize/Downsize your input image to 300 dpi.
  2. Remove color from the image. Grey scale is good. I actually used a dither threshold and made my input black and white.
  3. Cut out unnecessary junk from your image. For all three above I used netbpm (a set of image manipulation tools for unix) to get to point where I was getting pretty much 100 percent accuracy for what I needed.

If you have a highly customized font and go with tesseract alone you have to "Train" the system -- basically you have to feed a bunch of training data. This is well documented on the tesseract-ocr site. You essentially create a new "language" for your font and pass it in with the -l parameter.

The other training mechanism I found was with Ocropus using nueral net (bpnet) training. It requires a lot of input data to build a good statistical model.

In terms of invoking Tesseract/Ocropus are both C++. It won't be as simple as ReadLines(Image) but there is an API you can check out. You can also invoke via command line.

like image 130
Ish Avatar answered Oct 21 '22 01:10

Ish