This project is an interactive Ping Pong game that uses computer vision and hand tracking to create a unique gaming experience. Players use their hands as paddles to hit a virtual ball back and forth.
The game is a modern take on the classic Ping Pong. Instead of using physical paddles, players use their hands, which are tracked by a webcam. The game uses computer vision techniques to detect and track the players' hands in real-time.
- Hand Tracking: The game uses the
cvzone.HandTrackingModule
to detect and track the players' hands. - Virtual Paddles: Players' hands act as paddles. The game overlays virtual paddle images onto the detected hand positions.
- Dynamic Ball Movement: A virtual ball moves across the screen, bouncing off the top and bottom edges.
- Collision Detection: The game detects collisions between the ball and the paddles, changing the ball's direction accordingly.
- Scoring System: The game keeps track of each player's score, incrementing it when the opponent misses the ball.
- Game Over Screen: When a player misses the ball and it goes out of bounds, the game displays a "Game Over" screen with the final scores.
- Restart Functionality: Players can restart the game by pressing the 'r' key.
- Run the script and allow access to your webcam.
- Two players stand in front of the webcam, one on each side.
- Use your hands as paddles to hit the virtual ball back and forth.
- The ball will speed up with each hit, increasing the difficulty.
- Score points when your opponent misses the ball.
- The game ends when the ball goes out of bounds on either side.
- Press 'r' to restart the game at any time.
- Press 'q' to quit the application.
The game is built using Python and several key libraries:
- OpenCV (
cv2
): For image processing and display - cvzone: For hand tracking and image overlay
- NumPy: For numerical operations
The game utilizes computer vision techniques to create an immersive and interactive gaming experience without the need for physical controllers.
- Python 3.10 (the version used in the provided virtual environment)
- Webcam
-
Activate the provided virtual environment:
- On Windows:
venv310\Scripts\activate
- On macOS and Linux:
source venv310/bin/activate
You should see
(venv310)
appear at the beginning of your command line prompt, indicating that the virtual environment is active. - On Windows:
-
Verify that all required packages are installed:
pip list
You should see all necessary packages listed, including opencv-python, mediapipe, cvzone, numpy, and sympy.
-
Ensure your virtual environment is activated (you should see
(venv310)
in your command prompt). -
Run the main Python script:
python main.py
-
Allow the application to access your webcam when prompted.
-
Position yourself (and another player, if playing with two people) in front of the webcam.
-
Use your hands as paddles to play the game!
- Use your hands as paddles to hit the ball
- Press 'r' to restart the game
- Press 'q' to quit the application