Card Recognition Computer Vision – EENG 512 Matthew Runas Project Overview • Identify hands of blackjack real time • Allow for a player and a dealer to have designated hands – Determine initial value of hand – Player and dealer can hit or stay – Determine value of hand real time based on cards present in camera view – Display winner (and check for busts) Blackjack Properties • Uses card recognition for determining card and hand values • Each card in the video must be detected, then properties pulled – Card Value – Card suit – Card location Goal • Video feed will be split into two regions, dealer and player • For every card on the field, all properties are extracted and card value and suit displayed • Based on the two regions and current cards in those regions, a second window will be open displaying the current hands and winner Assumptions • All cards are from the same deck • All cards are on the same surface • Surface cards are on is of relatively high contrast • Lighting should be relatively similar on all cards Overall Algorithm • Opens video feed • For each frame – Runs card detection over whole frame, accounting for multiple cards (challenge) – Runs card recognition over each card – Checks which hand cards are a part of based on location – Outputs card properties to each hand – Outputs hand properties to score window Card Detection Algorithm • Algorithm run on each frame – Convert the frame to grey scale – Perform a Gaussian blur on each frame • Reduces noise on the frame, smoothing image – Perform a Canny filter on each frame • Detects edges based on changes in pixel values • Works well when paired with Gaussian blur – Contour each frame to finalize detection (using find contours) – Wrap a convex hull around each contour – Export the wrapped convex hull to separate image • Uses warp transform to go from one quadrilateral space to another Card Recognition Algorithm • Algorithm run on each frame of each exported card – Maps a 52 card library to a metric space using a gradient of pixel intensities • Everything can be compared relatively with a definitive distance (Hamming Distance) – Look at frame intensities, then compare frame relative intensities to library relative intensities – To get intensities of video and card library: • Down sample frame to an approximate 8x8 • Take the mean of all values in down sampled frame of the card • Threshold each bit to get a 0 or a 1 – Highest match will be the smallest Hamming distance Limitations • • • • Card must be on a high contrast surface Frame rate of the camera Computational speed of the computer Focal length must be similar to that of reference library • Overlapping or obstructed cards Demonstration https://www.youtube.com/watch?v=6eSwEcwo eno Possible Future Work • Be able to adjust for overlapping or obstructed cards – Definitely possible, just based on time constraint • Use less down sampling for comparing the relative intensities – Provides higher accuracy at the cost of more computing power • Combine with robotics to create a robotic blackjack dealer Questions?