Counting Cards Using Machine Learning and Python - RAIN MAN 2.0, Blackjack AI - Part 1
Ғылым және технология
RAIN MAN 2.0 is a card counting AI that's destined to be the ultimate blackjack player! Created using machine learning and Python, RAIN MAN 2.0 can easily count his way through a deck of playing cards. To identify cards, he uses a YOLO v3 detection model trained on 50,000 synthetically generated images.
This video explains how he works and what I plan to do with him. It's the first video in a series of videos that I will be posting as I build out his functionality.
-- Affiliate Links --
If you haven't seen the movie Rain Man, you need to watch it!! amzn.to/2XL7bit
Logitech C920 1080p webcam used by RAIN MAN 2.0: amzn.to/2WULb7B
Twitter: / edjeelectronics
RAIN MAN 2.0 project page on Hackaday: hackaday.io/project/27639-rai...
-- Links mentioned in video --
geaxgx1's playing card detection video:
• Playing card detection...
Wizard of Odds website, great source of blackjack information and strategy:
wizardofodds.com/games/blackj...
-- Music --
Summer Coffee by Barradeen:
/ summer-coffee
Hidden camera blackjack footage taken from Blackjack Army KZread channel: • Blackjack Card Countin...
Пікірлер: 194
I love thinking of a novel idea and then finding out it's not so novel
You are a trailblazer in the field of AI. You were ahead of the curve by 4 years.
Woah, can't wait to hear more about this project!
I don't play blackjack but I've been facinated about card counting. Your video is excellent as you answer all of the questions that came to my mind. I hope that you make a fortune--if not in a casino--by some killer apps other card games or for people with impaired vision. Let me know if you need investors!
Amazing. Youre doin really well. The video editing is top notch
@EdjeElectronics
5 жыл бұрын
Thanks man!!
This is amazing work! Very inspiring!
It seems like eventually this will also be able to deviate from basic strategy and even the card counting published deviations because the data will be more granular than simple high lo count. Very cool video.
Great work bro, love it and learning a lot from you ! You are beautiful man !
Ah ah I was wondering why I had a sudden spike in the count of my subscribers :-)) Thanks for the big shout out, bro ! Your project is really great, I am already impatient to watch the following parts and curious about the port on the raspberry ! Your video editing is excellent and you seem to have fun doing it (I know how time consuming this task is ;-) FYI, since the post of my video one year ago, I had the opportunity to test the following: take only one good picture of each card (instead of a video under varying lighting conditions) and rely on the image augmentation library to simulate the lighting. That works as well as previously, but is much less cumbersome. And good guess, you pronounce my id correctly !
@EdjeElectronics
5 жыл бұрын
Thanks friend! Your video and GitHub code helped me a ton. It's so satisfying watching the computer generate thousands of labeled images after you've spent hours labeling them by hand. I will have to try the one-card method on the next batch of cards I use for training. I will be keeping an eye on your channel too!
Awesome ... Endless implementation 👍👍👍
It’s my first year in CS. I thought about this last night woke up and found you lol
Wow, when you got into detail how we can help disabled people play as well with that just blew my mind and incorporates how we can help them exponentially advance in a game they can’t see or hear but with that device it’s and idea for a smaller compact use it would be incredible
genius! great video!
I love it when people do amazing AI projects like this! I hope you do more projects like this in the future (:
@EdjeElectronics
3 жыл бұрын
Thanks! I'm really hoping to start work on the next iteration of RAIN MAN soon. It's definitely a fun project!
Is the script to convert jpg to xml available? I already have the images but labeling them does not sound appealing
Can I take the images without webcam ? For example when I play on online casino.
We need part 2!
hi, when can i buy a the more compact model using raspberry , do you have 2 decks onboard yet? also, easy to find true count by dividing by remanings decks, cool u rock
Good video!
Hi. Could I get your frozen inference graph (.pb file) for playing cards?
This is amazing
I have a question. What were the specs of your pc? Do you need a high powered pc to make the neural network or can I make it on my raspberry pi 4? Also if I made it on my pc, can I make my pc give a physical output if it sees a “correct” card like turn on a led or move a servo? The raspberry pi has pins so I feel it would be easier on it.
How big of an Edge do you have if you use rainman 2.0. Because you can know exactly which Cards are left not just if they are High or low
I followed your program to train cards on windows 10. Followed each steps, I labelled 5 thousand cards but instead of labeling the whole card, I only label top right and bottom side manually. But after that it will not be able to detect anything.
Can you share the tensorflow model that you use here? Thanks
Question: What are you using to live stream the video from OpenCV? Are you just outputting the video result into a html page or something? Or perhaps streaming it somewhere? Im asking because im now getting started with Node.js and OpenCV4Nodejs using the Raspberry pi zero (With the same webcam lol). Right now im just taking an image every 200 mili-seconds and sending it to a node server to be viewed remotely. Theres a 2 second lag/delay. Thanks in advanced.
@EdjeElectronics
5 жыл бұрын
I'm just grabbing frames from the camera and displaying them using cv2.imshow() . You can see an example of how I do this on the Raspberry Pi starting at line 253 in my Pet Detector code: github.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi/blob/master/Pet_detector.py . I don't have any experience with Node.js or OpenCV4Nodejs, so I can't help there 🙁.
any soruce codes that we can take a look at?
Hahaha.... Super sir..very nice ..keep it up
I just watched a movie called Inside the Edge about a card counter (with other techniques that could be programmed). It got me curious about AI & what is / will be possible with technology. That's why I ended up here. Port it to Raspberry, get decent resolution on a pinhole tie or glasses cam (if that is an issue) and program the heck out of it. I know technologically cheating is illegal in NV, not so sure about statutes the other states? It would be a fun experiment to fleece casinos if legal elsewhere. (similar to MIT back in the day) Good luck with your project. It's a disruptive idea that's fun to think about!
how do make the GUI window? i mean when u detect the number of cards how do u show it just like 9:25 in ur video. thanks
@EdjeElectronics
4 жыл бұрын
At 9:25 in the video, that is actually just a "fake" GUI that I made using my video editor. The actual GUI (which you can see at 1:20 in the video) is made by using lots of drawing functions in OpenCV and PIL.
Any tips on how I would do a text based version of this? I want to start off with that before I work on my own counter using a camera or creating an oop simulator
@EdjeElectronics
5 жыл бұрын
Hmm.. what do you mean by a text-based version? Something like this? www.247blackjack.com/ I would search for "Optical Character Recognition Python" and look at some of the tools that are available for reading text using Python.
You definitely should do this for online casinos, man!
It was only mentioned in passing, but I am very interested in the potential for helping vision impaired people play cards. I've subscribed and will be looking for any developments in that area. Thanks!
This is awesome; I hope there can be an AI that will show us unforeseen approaches that only AI could find...
Did this ever get finished ?
Does this work in EMGU CV and c#? Personally I find card counting and visual ballistics a bit old school. Its better to use hardware and some special software to send the results back from the future.
@EdjeElectronics
3 жыл бұрын
Dang man you're thinking on a totally different level, I like it! This is my first time hearing of EMGU CV. Can you recommend a good site for me to read up on it and learn more?
Hi, excellent video! Any updates on the second part of the video? Also would the coral card help it to count more decks?
@EdjeElectronics
3 жыл бұрын
Thanks for your interest! I haven't had any time to work on RAIN MAN 2.0 since I published this video 😢. The coral would help speed up the Pi, but it can only run SSD-MobileNet models, which probably won't be accurate enough to detect the cards consistently.
You are a genius i love that you come this far in Development! Are you still working with this project
Can you share the playing card custom dataset? Thank you.
Hi i liked the idea of training images on synthetic data.. can you elaborate more on that
Oh - what an amazing video... could you share the yolo app or is it more than an app? I just want to build a simple app to recognize a card when it comes in front of the camera - If each playing card is fully visible to the camera would we we still need 50,000 images and a nn training for 8 hours?
@EdjeElectronics
2 жыл бұрын
Thanks! Unfortunately, I can't share the code for this project. The answer to your question depends on how complicated the scene is where you're detecting the card. If it's just one card against a constant background, you don't even need a neural network. You can use the method described in my OpenCV Playing Card Detection video ( kzread.info/dash/bejne/n2GFssyIXZWvm6Q.html ). If you want to use a NN, you can start with just 100 - 300 images or so, and see how that performs. My tutorial for doing that is a little outdated, but you can get a sense of how well it works by watching it ( kzread.info/dash/bejne/hJukyM1vlbzeeqQ.html ). Good luck with your project!
Can never use device in a casino as devices are against law, but we could point the camera at a computer monitor to count live online blackjack games, are you still working on this? I’d love to try it out on 6-8 deck online casino blackjack
@ascendordie7427
6 ай бұрын
Had the same thought hit me up. Let's cook.
@CodyNavin
5 ай бұрын
@@ascendordie7427 Same
@sonofappreciation
3 ай бұрын
This would work only for blackjack games where played cards get put into a discard tray instead of an automatic card shuffler.
Would you open source this if you are not going to continue it?
Seems like the best market would be create a trainer for new card counters (have it give you a mild shock when you make a mistake, LOL). Playing at a real table with real cards would better simulate real world conditions. Could also verify basic strategy and deviations (I've done some Python code for that, driven by different XML files according to which exact strategy to follow, based on the type of game).
@EdjeElectronics
4 жыл бұрын
I've been thinking about doing that! So far, that's the only actual use I've gotten out of this. It's probably the most practical application of this program, since it's a felony to try and use a card-counting device at a casino!
Hello How are you? Whats this code?
Great work! Any chance you've posted your python code publicly? I'd love to see the implementation.
@EdjeElectronics
5 жыл бұрын
Thanks! I'm keeping it closed-source for now. The flow is roughly similar to my Pet Detector project ( github.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi/blob/master/Pet_detector.py ) but with much more conditional logic and animation!
hey excuse me but please tell me how do you create a script who can only take the corners of your card please (thank you I love what you do)
@TheRealCraiDos
3 жыл бұрын
He explained it at 6:50
7:24 Bruh! 😂
Nice Wes Anderson collection! Where is The Darjeeling Limited?
@EdjeElectronics
Жыл бұрын
Wes Anderson is far and beyond my favorite director! I still need to get copies of Darjeeling Limited and Moonrise Kingdom.
do u have a Rain Man 2.1 or 3.0 yet? how much could one buy from you this amazing job you have done?
@EdjeElectronics
4 жыл бұрын
Thanks for the kind words! Unfortunately, I haven't had much time to work on it in the past year. I also don't plan to sell it any time soon.
Any update?
Goodjob
I want to make such a great application. How can I do?
Would love to see this for chess
May we have access to dataset please :)
@EdjeElectronics
4 жыл бұрын
This GitHub repository shows you how you can make it yourself! github.com/geaxgx/playing-card-detection
What happened to part 2? Was it ever improved? Great concept for winning blackjack at home with buddies lol
@eygs493
Жыл бұрын
lol
we need part 2!!!
@EdjeElectronics
3 жыл бұрын
I know!! Unfortunately (or fortunately), this video landed me a couple paid gigs related to playing card detection. I haven't had time to work on RAIN MAN! But I do have lots of ideas for Part 2, and will be able to work on it soon!
@freebird_music
3 жыл бұрын
@@EdjeElectronics nice! And congrats :) Could you try using it in an online casino next time? I feel like it would work out really good
Now I know why they don't what you used the Cell phone on the table
Can you program a rooted android with google eye and then you can have the google eyewear in the app
@russianreaper5925
4 жыл бұрын
BT-30C
Some casinos use continuous card decks - I bet this is quite a challenge for a ML application. How would you go about it?
@doxology1000
4 жыл бұрын
@Don C What about modelling your and each player's cards as a random variable and then implement this diff eq to get some deterministic thresholds on how or when to stop hitting (possiblywrong.wordpress.com/2014/06/27/the-price-is-right-puzzle-solution/) and then if you look at this paper (www.jstor.org/stable/27642600?seq=1) and combine it with the diff eqs , you essentially get the Nash equilibrium, which I think might give you some sort of edge. Not my idea wholly, but I think it has some value.
@EdjeElectronics
4 жыл бұрын
Cool discussion! Don C is right, there isn't really anything I could do about continuous shuffling machines (CSMs). However, they don't use those much here in the USA, because CSMs slow down the overall play. The less hands that can be played, the less money the casino makes - so casinos don't like using them. I hear they are more common in Europe.
Sir, I have successfully taken images of all 52 cards. 100 images/card and now I have already labeled 5200 images manually by hand using LabelImg software. I am going to run the training using SSD Mobile net and I have a plan to convert it into TF-lite on Pi. Sir please guide me that I am choosing the right path for this or not ?
@EdjeElectronics
4 жыл бұрын
Nice work! Yes, you are headed down the right path. I recommend training your SSD-MobileNet model and then testing it out on your Pi using the method I show in this guide: github.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi Then, once you confirm it works well enough, you can convert it to TFLite. The process for converting to TFLite is kind of difficult, but you can do it using this guide: github.com/EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi
Where is part 2?
Where's the part two?
Scary when computers are catching up to my photographic memory. I have a talent of remembering every card played … the family hates it
@peacekeepermoe
Жыл бұрын
Interesting. Do you use a technique like a memory palace? You just reminded of an article I read about this woman that can remember every single event from her past. She could not forget it even if she wanted to. I think her case (and many like her) is a blessing and a curse. I can't imagine that they would be able to 'forgive and forget' :(
@warlockzeroone
9 ай бұрын
are you rich yet?
Wish I had this data set.
Nice program
isn't there a better way to count cards/maximize odds? i mean this formula(0, +1, -1) is easier for humans, but with a computer you could count more accurate, considering every different value/card in the deck.
@EdjeElectronics
4 жыл бұрын
Yes, there definitely are! I'll be implementing a more advanced method for this AI than just basic +1 / -1 counting. I suppose the ultimate AI would calculate the exact probability of each outcome based on the remaining cards in the deck, and then select the best play based off that probability. It would take a lot of work to code that, though!
You can use it to play online at a casino.
@TodorescuProgramming
4 жыл бұрын
how do you know the online casion doesn't just spit out random cards ?
@Mc-en3hr
4 жыл бұрын
@@TodorescuProgramming online there are also real tables with real croupiers, just change the feed of the webcam with that of the screen.
Hi, Is it possible to share the dataset or the weights you train? I have 2 days left for my term paper. That's why I want it.
@ScottFioreAP
4 жыл бұрын
Rip
This needs more attention.
HI Speed HQ cam in glases, wireless transporting to a box on the ancle sending to a computer in a van parked outside. Can you implement Basic Strategy in your system, to tell you to Hit, Split, Stand og DD ?
Yoooo let meee get thisssd
Did you ever release this into public? Im very interested
@EdjeElectronics
Жыл бұрын
Nope :( but you can find a similar training dataset here if you want to try to train your own model! universe.roboflow.com/augmented-startups/playing-cards-ow27d
@90014929
Жыл бұрын
@@EdjeElectronics will you ever release your version I'm willing to pay good money for it?...
@warlockzeroone
9 ай бұрын
i made one.
@KEKW-lc4xi
7 ай бұрын
@@90014929 but why though? Did you watch the video all the way through before commenting?
how about online casinos
@Mp-jw1qg
Жыл бұрын
it would be cool to run it just to see if the online casinos are actually using the right amount of decks etc.
how to download it?
Can I invest money with this project of yours?
can you share the code
@khalilgibran1525
5 жыл бұрын
Hahahaha
Not an open source project. I was very curious.
Hahahah you're funny man
hey man wheres the git repo
can this work on online casino's?
@EdjeElectronics
4 жыл бұрын
That's the end goal 😎
@Gamma4K
4 жыл бұрын
HOSTOBI HD For sure it works, you can even type the cards that are dealt on to your computer haha
Live dealer?
maybe try one of those google smart glasses
Im trying to do a program like this but for texas holdem. Kind of like zynga poker hand percentage chance but its for playing with the boys and something I can just pull out on my phone. Almost like a referee so we can get a accurate winner and not have a debate on who wins the pot.
if you want to take it to a casino your best bet is to run it on AR glasses such as the NReal Air
@sandplanet471
Жыл бұрын
I’m planning on making an app like this which displays the running count on one side of your view and the best play for that hand based on basic strategy on the other.
DUDE IF IT"S ABOUT THE COMPUTER SIZE WHY NOT CONSIDER LATTE PANDA, BAREBONE PCS, BEELINK AND IF IT'S THE CAM TRY FPV DRONE CAMS
Hi, I am very impressed with your project. It seems very nice and I would like to try to do it myself. Can you share your github? Thanks
COOL BEANS
great idea that ive only just thought of years later, taking customers?
Great video, GitHub link?
@EdjeElectronics
5 жыл бұрын
Thank you! I haven't uploaded this one to GitHub. See my response to the previous comment 😃
I have a work around and its genuis and if I thought of this I bet you have to
@michaeldrew7613
2 жыл бұрын
What is it
definitely, definitely a good bot
you could have a tiny cam hidden inside your hair, it would rout the footage trough a smart phone and forward it to some cloud computing provider like aws, once the results are processed which should be fairly quick, you would have them read back to you trough a micro Bluetooth earpiece. but then again why go trough the trouble when you could just learn card counting which isn't that difficult to begin with
@sdrfz
2 жыл бұрын
Or perhaps mount a camera in some glasses, like google glass. Then have a bluetooth client in the glasses communicate the card data to a nearby battery-powered compute module that runs the AI algorithm and is hidden in a purse or backpack. The glasses could have a vibration motor to indicate the optimized bet. You could also implement a more accurate and sophisticated card detection and betting algorithm, one that an ordinary human would not be able to match.
@vuufke4327
2 жыл бұрын
@@sdrfz the issue with is card counting does not work anymore, the decks are too large they have continuous shuffling machines and the pit master always knows when you're counting because you keep changing the bets in very predictable situations.. there was a guy that used a camera and a computer in his shoe to calculate the physics of the roulette, that was back in the 80s he's the sam guy that created card counting I forgot his name
@sdrfz
2 жыл бұрын
@@vuufke4327 You say the decks are too large, does that mean even with identification of the specific cards that come out (and not just a counting of cards), the computer algorithm would never be able to gain an advantage? Also could you change the computer betting algorithm such that it is inconsistent and does not always maximize the odds of winning (but still gives you the winning edge) in order to deceive the pit master?
@vuufke4327
2 жыл бұрын
@@sdrfz Changing the location or betting online with different accounts is an easy solution to this issue.. don't even concern yourself with any computer vision issue you could just input the cards manually from a separate window, but the main problem you have on your hands at the moment is developing some algo that predicts the most likely structure of 6 decks of cards based on the 10 or so cards the dealer has revealed, and then adjusting your bets dynamically based on the next likely outcome, believe me that's no walk in the park, that alone would be something that an entire group of researcher might not be able to pull off with years of work.. and if you do this don't follow basic strategy, according to some papers I read online the best basic strategy keeps changing as the game progresses and is not just a deterministic mechanical system, if you can do this, you won't have to worry about getting caught cheatings. to any unsuspecting observer your actions would seem completely arbitrary with a small dab of logical action here and there, basically it would just look like you're just a lucky bastard
@sdrfz
2 жыл бұрын
@@vuufke4327 I would think manually typing in the card would be too obvious at a BJ table in front of the dealer and casino cameras. You don't want to follow the optimal strategy because that might tip off the casino that you are counting cards. Instead place fixed bets for a period of time, then increase the fixed bet when the odds turn in your favor, rather than a continuous up/down bet strategy after every hand. I doubt it would require years of work to come up with a semi-optimal strategy that would still win you money in the long term and fool the casino.
Make some code for online gambling
Cool vid but, running count is wrong after dealt round after running count of 15. Should be 10, not 8. Hope the computer got it right. LOL.
Part 2 ? :-)
@EdjeElectronics
3 жыл бұрын
Haha... I wish 😭😭😭 maybe someday! I have my own consulting company now, and it doesn't leave me much time for KZread. But I'm hoping to get back into eventually!
@bachel9569
3 жыл бұрын
@@EdjeElectronics Thats great to hear! and all the best! maybe publish the code on github :-) So we dont have to start from 0 :-)
Ok but what if Casino have an CSM (Shuffle-Machine)
@EdjeElectronics
4 жыл бұрын
Then I'm screwed 😂! But I've never seen a casino that uses a CSM for blackjack... and I've been to a lot of casinos!
@KenDandKrisD
4 жыл бұрын
Edje Electronics come Vancouver, BC and you’ll see.
@chinesefood2
4 жыл бұрын
I work on a casino with all csm 😂
Amazing job! I had the same idea few months ago, but I can't coding.
By now aren't there laws against using AI in casinos? Its like athletes using steroids..
@EdjeElectronics
5 жыл бұрын
Yep... in Nevada, it's NRS 465.075. One to six years jail time and/or up to a $10,000 fine. Yikes! www.leg.state.nv.us/nrs/nrs-465.html#NRS465Sec075
ever heard goliath shoe computer?
@EdjeElectronics
5 жыл бұрын
No I haven't, what's that?
@SOLINAKIAS
4 жыл бұрын
@@EdjeElectronics small computer back in the 80s hidden in a shoe entering the values with toes keyboard