Linus
Linus

Reputation: 2819

OpenCV detect numbers

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?

Upvotes: 20

Views: 56516

Answers (10)

Jaime Ivan Cervantes
Jaime Ivan Cervantes

Reputation: 3697

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[dead link]. 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[dead link].

Upvotes: 8

Krish
Krish

Reputation: 1827

Convolution Neural Networks are by far the best algorithms for hand written digits. The are implemented in most systems like USPS etc. Here are few papers explaining the algorithms. http://yann.lecun.com/exdb/lenet/

Upvotes: 1

Alex Hoppus
Alex Hoppus

Reputation: 3935

HOG + SVM (Try to play with kernels)

Upvotes: 0

bellkev
bellkev

Reputation: 925

Tesseract is also a nice free OCR engine that is readily available for iPhone and allows you to use your own sets of training images: http://tinsuke.wordpress.com/2011/11/01/how-to-compile-and-use-tesseract-3-01-on-ios-sdk-5/

Upvotes: 0

divanshu
divanshu

Reputation: 345

Simple Digit Recognition OCR in OpenCV-Python

This might help you out. Converting the code from Python to C++ is not a difficult task, since OpenCV API's are same for the both.

Upvotes: 0

shihongzhi
shihongzhi

Reputation: 1931

This is a nice open source ,It is a ORCDemo on iPhone.Hope it is useful to you

Upvotes: 0

Rob Audenaerde
Rob Audenaerde

Reputation: 20029

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.

Upvotes: 5

Alex Hoppus
Alex Hoppus

Reputation: 3935

Maybe the most simple and convinient way is to use svm as ml algorithm http://opencv.willowgarage.com/documentation/cpp/support_vector_machines.html and gray images as feature vectors.

Upvotes: 2

crenate
crenate

Reputation: 3482

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.

Upvotes: 2

melps
melps

Reputation: 1247

Objective C++? Try renaming your .m files to .mm and you can then use c++ in your iPhone project.

Upvotes: 1

Related Questions