views:

995

answers:

7
+7  Q: 

OCR Playing Cards

I decided to do a project for fun where I want to take as input the image of a playing card and return its rank and suit. I figure that I only need look at the upper-left corner, since that has all the information. It should be robust - if I have a large image of an Ace of Diamonds, I should be able to scale it anywhere from 20 to 200% and still get the right answer.

First question - is there anything already written that does this? If so I'll find something else to OCR so I don't duplicate the efforts.

Second - what's the best way to go about doing this? Neural network? Something hand-coded? Can anyone give any pointers? (0xCAAF9452 is not an acceptable answer).

A: 

Check out http://d-touch.org/, you would have to design your own playing cards though.

You might also be interested in ocropus.

joeforker
you're taking it the opposite way - i'm given playing cards and have to OCR them, i dont have to deisgn playing cards that are OCR-abe=)
+2  A: 

I don't think there's something already written for what you are trying to accomplish (at least open source and in Python).

As for your second question, it depends on what you are trying to recognize. If the inputs can come from different sources -- e.g., different brands of playing cards with distinctive styles --, then you should probably use a machine learning-based algorithm (such as neural network or support vector machine [SVM]), in order to let it learn how to recognize unknown inputs. However, if the input is always the same in shape or style, then a simple image comparison algorithm will suffice (e.g., compare the pixels of the sliced upper-left corner with the pixels of each rank).

If you do decide to use a machine learning-based algorithm, I also think you don't need very complex features, as the suits and ranks don't really vary that much in shape or style, and you should be fine with using just the pixels of the upper left corner as features.

There's a toy OCR example here that you may find interesting. The lib that is used (LibSVM) also has a Python version, which I have used, and found very simple to work with.

Hope it helps.

JG
A: 

Its not as robust, but you can pixel match 3 or 4 locations on the card so that if they are white or if they are a color, you can determine which card and suite it is. Obviously this won't work if you don't always have the same cards.

redblacktree
A: 

Personally I would go the machine learning route with this one.

DevDevDev
Why would you need machine learning when the problem is so specific?
kigurai
Maybe I misunderstood the problem, but the OP is taking photographic images of cards and trying to deduce their rank and suit correct?
DevDevDev
I agree. You get an upvote to compensate the others : ).
JG
+4  A: 

There is a bunch of material online about this in the context of building online poker bots. See, for example: http://www.codingthewheel.com/archives/ocr-online-poker-optical-character-recognition

Andrew Medico
A: 

Given the limited sample size (4 suits, 13 different values) I'd just try to match a reference image of the suit and value with a new input image. First find the bounding box of the incoming suit / value (the smallest box enclosing all non-white pixels), scale your reference pictures to match the size of that bounding box, and find the best "match" through pixel-wise absolute difference. The colour of the picture (i.e. red or black) will make this even easier.

jilles de wit
+1  A: 

Use OpenCV

Szczepan
thanks for the link!
+1 OpenCV certainly provides a good toolbox.
kenny