OpenCV detect numbers

Linus picture Linus · May 3, 2011 · Viewed 49.9k times · Source

I'm using OpenCV on the iPhone and need to detect numbers in an image. I split the image into smaller images so each image has only one number (1-9). All numbers are printed, NOT handwritten.

What would be the best approach to figure out the numbers with OpenCV?

UPDATE:

I have successfully found the numbers and extracted them. They look like this:

http://img198.imageshack.us/img198/5671/101ht.jpg
http://img824.imageshack.us/img824/539/606yu.jpg

When they are extracted they are in the same size and so on. I have saved a bunch of images and put them in a OCR dir where they are categorized into numbers. Like: ocr/1/100.jpg 101.jpg.... and ocr/2/200.jpg 201.jpg....

Then I was going to use the same approach as in the Basic OCR tutorial:http://blog.damiles.com/?p=93

However, I'm programming for iPhone and can't use C++ code (error on compiling and so on) and I don't have access to highgui.

I tried using cvMatchTemplate() and match a bunch of images but it seems to work pretty bad...

Any other ideas I can try?

Answer

Jaime Ivan Cervantes picture Jaime Ivan Cervantes · May 23, 2012

You could start by reading about Principal Component Analysis (PCA), Fisher's Linear Discriminant Analysis (LDA), and Support Vector Machines (SVMs). These are classification methods that are extremely useful for OCR, and there are libraries in any language including C++, Python, C# etc.

It turns out that OpenCV already includes excellent implementations on PCAs and SVMs. I haven't seen any OpenCV code examples for OCR, but you can use some modified version of face classification to perform character classification. An excellent resource for face recognition code for OpenCV is this website.