Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV detect numbers

Tags:

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?

like image 935
Linus Avatar asked May 03 '11 17:05

Linus


People also ask

What is OpenCV Python?

OpenCV-Python is a library of Python bindings designed to solve computer vision problems. Python is a general purpose programming language started by Guido van Rossum that became very popular very quickly, mainly because of its simplicity and code readability.


3 Answers

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.

like image 59
Jaime Ivan Cervantes Avatar answered Oct 06 '22 01:10

Jaime Ivan Cervantes


If the numbers are printed, the job is quite simple, you just need to figure out a nice set of features to match. If the numbers are one font, you can get away with this approach:

  • Extract the number
  • Find the bounding box
  • Scale the image down to something like 10x8, try to match the aspect ratio
  • Do this for a small training set, take the 'average' image for each number

  • For new images, follow the steps above, but the last is just a absolute image difference with each of the number-templates. Then take the sum of the differences (pixels in the difference image). The one with the minimum is your number.

All above are basic OpenCV operations.

like image 38
Rob Audenaerde Avatar answered Oct 06 '22 00:10

Rob Audenaerde


Basically your problem is just to classify a feature vector, which is the set of pixel intensities after some preprocessing steps. You can use any classifier for this task, like eg. neural networks, which should have a C implementation inside OpenCV. You might also try a C libsvm library for Support Vector Machines.

There is a good site related to this problem with a lot of papers and a training database.

like image 28
crenate Avatar answered Oct 06 '22 01:10

crenate