OCR Playing Cards

2019-03-15 12:00发布

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).

7条回答
We Are One
2楼-- · 2019-03-15 12:39

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.

查看更多
疯言疯语
3楼-- · 2019-03-15 12:45

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.

查看更多
孤傲高冷的网名
4楼-- · 2019-03-15 12:48

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

You might also be interested in ocropus.

查看更多
趁早两清
5楼-- · 2019-03-15 12:51

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

查看更多
老娘就宠你
6楼-- · 2019-03-15 12:52

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

查看更多
beautiful°
7楼-- · 2019-03-15 12:55
登录 后发表回答