Final Project : Poker bot
CS 585 Project Results
Lang Gao
Seunghun Oh

In this project we attempted to build a program that could play poker with humans
on a physical poker board. To do this the program used a camera to look at the playing
board and extract information about what has happened since the last time it looked, and
determine what happened and what it should do in response.


The following is a screencap of the program running. The green box is the pot, the blue middle
box is the player's pot and the red box is the program's pot. The cyan box is the player's hand
and the long black box is the board(cards displayed for all).

We first found the largest contour (as the largest contours will contain the most accurate size as well
as the card itself. Then, We extracted the card by selecting a certain area as a scan zone. Finally, We performed
absolute differencing with different templates in order to determine which template corresponded best with
the image. After returning the image, we performed poker's logic and algorithms to play the game.

The following images are a sample largest contour, an example of absolute differencing at work, and
a sample matched value for suites.


The results of our project was that we were able to build a system that can somewhat
analyze physical cards and obtain their suit and value, and use that to estimate how
good or bad of a hand the computer was dealt based on cards revealed as the round progressed.

The card reading was the most challenging part of our project, as getting the values
from the cards proved to be a greater challenge than expected, and our initial plans
did not work, as template matching was not good enough to determine card values, and
we had various issues trying to get tesseract (and its OCR functions) working.

Determining how many chips each player had was mildly successful. We decided to
guess based on how much area in each player's designated chip spot was occupied by
each color. We decided against trying to seperate out individual chips since they
clumpted together rather easily and in that case chips with the same color would be
rather difficult to seperate, and in a real poker game the chips would be stacked on
top of one another.
Having the player indicate when the computer should analyze the next frame worked
fairly well as long as the player did not purposly mess with that area of the camera.
We ignored a lot of the frames recorded, as we only wanted to analyze the state of the
board at the end of each state. We originally had the idea to look at every frame
to have the computer identify when it was supposed to perform specific actions
but we realized that it would be quite hard to seperate actions from just general
motion and specific objects to be analyzed would still have to be in predetermined
locations to achieve good results anyways.

Future Work

In the future, we would like to futher improve the letter recognition for our program.
This desire is because this setback is the biggest factor to why our program was not able to
perform fully as we wished. We would also like to add in facial feaeture recognition to further
emulate a human player using emotions.

A potential way for recognizing cards that we would like ti implement is a neural net with
trained data. A trained neural net will help us recognize the letters very accurately.