Skip to content

Classic childhood game Rock, Paper, Scissors but make it computer vision

Notifications You must be signed in to change notification settings

ichennnn/rps_comvis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rps_comvis

rps_comvis is your classic, childhood game of Rock-Paper-Scissors, but upgraded with the addition of computer vision tools. This reimagined version detects hand gestures with a computer webcam and allows for player to play with computer using real-time hand gestures.

rps-gif-small

This was built as a practice project to explore computer vision.

Rules of Rock Paper Scissors

The rules of the game can be succinctly summarized as:

  • Rock beats Scissors
  • Scissors beats Paper
  • Paper beats Rock

When opponents chose the same gesture, the game is a draw. Hence, the only three outcomes are : Win, Lose and Draw.

Nuances of Hand Gestures

Hand gestures are detected through the usage of OpenCV and MediaPipe. MediaPipe detects gestures through the 21 landmarks as shown below. image (Source: https://google.github.io/mediapipe/solutions/hands.html )

To avoid misreading of gestures, only one hand is detected at a time. To detect the three hand gestures, I consider the cases:

  • Is the 4th finger down? (Look at Landmark 16 and 13)
  • Is the 3rd finger down? (Landmark 12 and 9)
  • Is the index finger down? (Landmark 8 and 6)

If 4th, 3rd, and index fingers are down, then gesture is assumed to be rock. If only 4th and 3rd finger are down, then gesture is assumed to be scissors. While if all three are not down, then gesture is assumed to be paper.

Python Libraries Used, Technologies

Python 3.8.8

  • OpenCV (cv2), Pygame, time, os, random, Mediapipe

Usage, Installation

Download rps-comvis by cloning this repo

git clone https://github.com/ichennnn/rps_comvis.git

The necessary Python libraries may be installed as such:

pip install mediapipe
pip install pygame
pip install opencv-python

How to Run?

cd rps_comvis
python game_app.py

Acknowledgements

rps-comvis game's HandTrackingModule was based on 'Murtaza's Workshop - Robotics and AI' 's video (on YouTube and here) with modifications to detect different gestures.

Hand gesture images are drawn by myself.

About

Classic childhood game Rock, Paper, Scissors but make it computer vision

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages