This project extends the traditional game of rock paper scissors to 5 hand signs, featuring AI and computer vision. It leverages a Random Forest classifier and OpenCV for real-time hand sign recognition and winner determination.
RPSLS.Demo.mp4
Random Forest is chosen for its robustness and ability to handle a large number of input variables. It creates a 'forest' of decision trees, each trained on a random subset of the training data. The final prediction is made by aggregating the predictions of all individual trees, reducing overfitting and improving accuracy.
OpenCV (Open Source Computer Vision Library) is used for real-time image processing. It captures video from the webcam, processes the frames to detect and recognize hand signs, and feeds the processed data into the Random Forest classifier. OpenCV provides various tools for image processing, such as contour detection, image filtering, and feature extraction, which are essential for accurately identifying hand signs.
- Before you start, ensure you have all the necessary modules installed by running 'pip install requirements.txt' inside the project directory terminal (ideally within a virtual environment).
- Run
game.py. - Start the game by pressing the 's' key.
- Show your hand sign to the camera.
- The AI will also choose a hand sign.
- The winner will be displayed on the screen.
- To end the game, press the 'q' key.
https://images.app.goo.gl/eg7f5pxQUEsiCEXAA
The rules of the game are as follows:
- Rock crushes Scissors
- Scissors cuts Paper
- Paper covers Rock
- Rock crushes Lizard
- Lizard poisons Spock
- Spock smashes Scissors
- Scissors decapitates Lizard
- Lizard eats Paper
- Paper disproves Spock
- Spock vaporizes Rock
- Activate training mode by pressing the 't' key.
- Select a training slot (0-9) by pressing the corresponding number key.
- Training slots 0-4 correspond to rock, paper, scissors, lizard, and spock respectively.
- Additional training slots are included, allowing further extension of the game to train more hand signs.
- Show your hand sign to the camera and press 'c' to capture the data.
- The captured data will be saved to
./model/training/training_data.csv. - Execute
handSignClassifier.ipynbto train the model with the captured data. - Switch training slots after training a hand sign.
The training data is stored in a CSV file located at ./model/training/training_data.csv. Each row in the CSV file represents a single training example and contains the following fields:
-
Label: An integer representing the hand sign (0-4) where:
- 0: Rock
- 1: Paper
- 2: Scissors
- 3: Lizard
- 4: Spock
-
Handedness: A string indicating whether the hand is "Left" or "Right".
-
Landmarks: A list of normalized 3D coordinates (x, y, z) for each hand landmark. The landmarks are normalized based on the bounding box of the hand to ensure consistency across different hand sizes and positions.
Example of a single row in the CSV file:
0,Right,"[[0.6851851851851852, 1.0, 0.0], [0.35185185185185186, 0.8428571428571429, -0.11428571428571428], ...]"