News for hackers. Stuff that matters.
Re:Automating Card Games Using OpenCV and Python by jrockway on Sunday June 16, 2013 @06:22PM (#5890275)
The real takeaway from this article is that O(n^2) and O(n!) algorithms are fine when your input size is 52 and 4.
Re:Automating Card Games Using OpenCV and Python by arnabdotorg on Sunday June 16, 2013 @06:46PM (#5890375)
Haha, sure. Since this was a random fun project, the code was written with the objective function being "least amount of code to get the job done well enough" :)
Re:Automating Card Games Using OpenCV and Python by skeletonjelly on Sunday June 16, 2013 @09:10PM (#5890842)
As it should! Too often I get stuck in a rut, inspired by the myriad of articles I read about certain patterns and libraries, that I take too long to get a simple task done with my head in the wrong space. Good work! You can't refactor code you've haven't written.
Re:Automating Card Games Using OpenCV and Python by icefox on Monday June 17, 2013 @08:01AM (#5892661)
In a similar vein, the complexity and suggested data structures for the input sizes: http://www.infoarena.ro/blog/numbers-everyone-should-know
Re:Automating Card Games Using OpenCV and Python by arnabdotorg on Sunday June 16, 2013 @06:38PM (#5890343)
Hi guys, author of the blog post here. I put up the code from the blog post at

https://github.com/arnabdotorg/Playing-Card-Recognition

if anyone wants to play with it.

Re:Automating Card Games Using OpenCV and Python by danso on Sunday June 16, 2013 @05:45PM (#5890153)
I love this...I play around with OpenCV as much as a Rubyist can (with our kind-of-maintained wrapper) and would learn Python just to make better use of OpenCV...I don't know if what OP is doing is the most efficient way computationally, but it sure is clever, at least for me :)

For instance, recognizing the cards in an image...my first approach would've been to try to identify the numbers/letters of the cards...which would've been just stupid...but the OP's strategy of using findContours and simply choosing the four largest rectangles is elegant...in the way that OpenCV is so powerful you can problem-solve at a fairly high level.

Re:Automating Card Games Using OpenCV and Python by Bjoern on Sunday June 16, 2013 @07:27PM (#5890519)
If you enjoyed this article, then the following one describing a sodoku solver will be fun too.

http://sudokugrab.blogspot.co.uk/2009/07/how-does-it-all-wor... http://www.aishack.in/2010/08/sudoku-grabber-with-opencv/

Re:Automating Card Games Using OpenCV and Python by elteto on Monday June 17, 2013 @01:55AM (#5891662)
For a more robust image registration, SIFT [1] could have been used too. SIFT is nothing short of amazing, capable of matching images under different rotations and scales. I'm pretty sure OpenCV has good support for it.

[1] http://en.wikipedia.org/wiki/Scale-invariant_feature_transfo...

Re:Automating Card Games Using OpenCV and Python by joshu on Monday June 17, 2013 @02:42AM (#5891787)
Have you actually used it?
Re:Automating Card Games Using OpenCV and Python by elteto on Monday June 17, 2013 @05:13PM (#5895994)
I have not, but I'm working on a project where I will use it to extract features from an image and use it to register two point clouds. There are many other algorithms for doing the same thing, but I have read that SIFT is very robust.
Re:Automating Card Games Using OpenCV and Python by sirsar on Sunday June 16, 2013 @08:44PM (#5890751)
Here's 58 solutions in 58 languages, for the algorithmically curious: http://rosettacode.org/wiki/24_game
Re:Automating Card Games Using OpenCV and Python by guiambros on Tuesday June 18, 2013 @12:42AM (#5897593)
This is rather interesting. Have you thought about the conflict of interest between Google Glass and casinos? Very soon you won't need to count cards anymore; you can just walk in with your glasses on and OpenCV recognition.

Heck, you may not even need OpenCV. Just livestream, and let somebody far away tell you the probabilities..

Very soon they'll be banning Google Glasses from Las Vegas. Or any glasses, for that matter.

EDIT: ok, seems I'm the last person on earth to arrive in this conclusion: http://www.foxnews.com/tech/2013/06/06/casinos-ban-gamblers-... We'll have to wait till Google Contact Lenses.

Re:Automating Card Games Using OpenCV and Python by double051 on Sunday June 16, 2013 @07:30PM (#5890526)
Very cool! Provokes the thought of doing something similar for Magic: the Gathering as well.

Missed triggers no more!

Re:Automating Card Games Using OpenCV and Python by iandanforth on Monday June 17, 2013 @11:23AM (#5893682)
Neat idea, do it!
Re:Automating Card Games Using OpenCV and Python by RK on Sunday June 16, 2013 @07:51PM (#5890600)
Is this for cheating at cards with Google Glass? :)
Re:Automating Card Games Using OpenCV and Python by waterside81 on Sunday June 16, 2013 @08:09PM (#5890658)
I wonder if casinos will start banning people from wearing Glass. I guess you could write some CV software to keep track of cards and then automatically display your probabilities, kind of like the graphics they show on TV when broadcasting poker.
Re:Automating Card Games Using OpenCV and Python by jluxenberg on Sunday June 16, 2013 @09:40PM (#5890934)
It's already the law in Nevada; NRS 465.075  "Use or possession of device to obtain advantage at playing game in licensed gaming establishment"

http://www.leg.state.nv.us/NRS/NRS-465.html#NRS465Sec075

Re:Automating Card Games Using OpenCV and Python by nknighthb on Sunday June 16, 2013 @11:10PM (#5891214)
There's going to be a problem when technology reaches the point that it's practical to embed a general-purpose computer with a decent neural interface in your skull.
Re:Automating Card Games Using OpenCV and Python by nobodyshere on Monday June 17, 2013 @04:49AM (#5892124)
Don't worry, they'll just create some scanner capable of finding out whether you have some stuff like that or not as early as at entrance.
Re:Automating Card Games Using OpenCV and Python by reeses on Monday June 17, 2013 @01:34AM (#5891619)
I'm way ahead of you there.
Re:Automating Card Games Using OpenCV and Python by MBCook on Sunday June 16, 2013 @11:01PM (#5891188)
And state gaming commissions are issuing directives to make it clear that Google Glass shouldn't be allowed.

http://www.foxnews.com/tech/2013/06/06/casinos-ban-gamblers-...

Re:Automating Card Games Using OpenCV and Python by troels on Monday June 17, 2013 @02:41AM (#5891780)
I wonder how they define "device". Does my contact lenses count? Arguably they give me quite an advantage over not wearing them.
Re:Automating Card Games Using OpenCV and Python by dinkumthinkum on Sunday June 16, 2013 @08:42PM (#5890746)
You're not even allowed to where the glasses that assist you with marking cards, I think Google Glass is probably out of the picture as well. :)
Re:Automating Card Games Using OpenCV and Python by pbhjpbhj on Sunday June 16, 2013 @07:16PM (#5890472)
Nice. I'm thinking this would be cool to develop as a computer player to other meatspace card-games.

Stand your tablet up at the table, have a rack for their cards and deal them in to your game.

Re:Automating Card Games Using OpenCV and Python by dedward on Sunday June 16, 2013 @10:30PM (#5891083)
It's been done, albeit a bit simpler, to cheat/assist in collusion in online poker.

You don't have an API (for obvious reasons) into the poker clients, so you have software that basically reads the screen as an image and works the keyboard/mouse.... the more sophisticated ones do it in a VM to avoid detection (some poker software actively scans your machine for known bot software or other tampering)

Re:Automating Card Games Using OpenCV and Python by zwieback on Monday June 17, 2013 @08:50AM (#5892829)
Very nice. Many years ago I built a machine vision system to inspect Playskool ABC blocks with the same method. I added some erosion to the images of the parts and some dilation to the template images. That way there's a little wiggle room to account for different temperatures of the branding iron and the press that made the embossed letters.

The thing worked pretty well, unfortunately production moved overseas and the company that made the blocks is gone now.

Re:Automating Card Games Using OpenCV and Python by foxhop on Sunday June 16, 2013 @08:32PM (#5890725)
I was just messing with OpenCV + Python + PIL today, I wrote a script that finds all the faces of an image on the net and puts a smile-face on top.
Re:Automating Card Games Using OpenCV and Python by kbutler on Monday June 17, 2013 @10:09AM (#5893202)
Sounds fun - will you please post the code?
Re:Automating Card Games Using OpenCV and Python by ragebol on Monday June 17, 2013 @02:11AM (#5891704)
Awesome, reminds me I really need to port my C#+EmguCV (https://github.com/yol/SetVision) program to play Set to Python. Its funny that recognizing the cards in Set is easy for humans and the combinatoric stuff hard, while for computers, it's exactly opposite.
Re:Automating Card Games Using OpenCV and Python by nobodyshere on Sunday June 16, 2013 @04:36PM (#5889841)
Looks interesting. Always glad to see any decent OpenCV example with python.