Git Product home page Git Product logo

chetannair / rock-paper-scissors Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 2.0 26 KB

An application with which the user can play Rock, Paper, Scissors. Uses OpenCV and Mediapipe to take a video input from the webcam and classify the hand as "Rock", "Paper", or "Scissor". The application then provides its own random output as a "play" and calculates the winner.

License: MIT License

Python 100.00%

rock-paper-scissors's Introduction

OpenCV Rock, Paper, Scissors

Overview

  • The user can play a game of rock, paper, scissors against the computer.
  • Uses video input from the webcam to capture the user's move (rock, paper or scissors).
  • The computer also generates its move.

The winner is calculated and the scores are incremented appropriately. Ties contribute zero points while invalid hand signs are reported as invalid by the program.

Getting Started

Dependencies

Program Execution

python3 RPS_Game.py

** Must allow the program to use webcam.

Detailed Explanation

Using OpenCV, the webcam input is read in frame by frame. The mediapipe library's hand module is called and isolates the hand's skeletal structure if it is in frame. An alogrithm* decides whether the player's move is rock, paper or scissors using the skeletal coordinates from the module and the computer also plays a move. The user then needs to move their hand out of the frame and back in to play the next round. The winner is calculated each time the hand enters back into the frame after leaving and a running tally is maintained.

*This algorithm works by counting the number of fingers that are open. For rock, this would be zero. This scissors, this would be two fingers. And finally, for paper, this would be 5 fingers. The number of fingers is counted by checking the y-coordinate of different finger segments. If the fingertip is below the middle of the same finger, it is considers closed. Hence, it does not count towards the number of open fingers. For the thumb, the x-coordinate is used. The limitation of this strategy is that the palm needs to face the camera in order for the open fingers to be counted properly.

Author

Chetan Nair - [email protected]

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.