Skip to content

⚡A computer vision game in which the user is able to a tumble blocks using a ball tracked in real-time

Notifications You must be signed in to change notification settings

mohdalibn/cv-ball-tracking-game

Repository files navigation

cv-ball-tracking-game

Main Project Image

GameMainMenu

GamePlayScreen

project-description (11)

The CV Ball Tracking Game is a Computer Vision project in which the user is able to control the ball in-game using a Red Colored Ball where the image data is fed through their Webcam/Camera. The game is made using Unity and scripts handling the recieving of data and logics were all were written in C#. The Python Script and the Unity Game communicated through a UDP connection. The screen coordinates of the ball are extracted using OpenCV through the custom HSVColorDetector module. This data is then encoded and sent from the Python Script using the socket library to the game which is then received by a C# script which decodes it, and is used by the other logical C# scripts to update the ball's position on the game screen.

technologies-used (11)

C# Python Python Socket OpenCV NumPy Unity

how-to-use-project (6)

Download & Install Unity hub: https://unity3d.com/get-unity/download

Download & Install Unity Editor 2020.30f1: https://unity3d.com/unity/whats-new/2020.3.0

Download the CV Ball Tracking Game folder: https://www.mediafire.com/folder/56ctovga52bwc/CV_Ball_Tracking_Game

Install the LeanTween asset for Unity from the asset store: https://assetstore.unity.com/packages/tools/animation/leantween-3595

Install the following Python libraries in your Virtual Environment using PIP.

Note: The library names are CASE-SENSITIVE for PIP installations below. Make sure your type them correctly.

Install OpenCV for Python

pip install opencv-python

Install Numpy for Python

pip install numpy

Download a copy of this repository onto your local machine and extract it into a suitable folder.

  • Create a Virtual Environment in that folder.
  • Install all the required Python libraries mentioned above.
  • Install Unity Hub & Unity Editor using the links above.
  • After the previous step, download the CV Ball Tracking Game folder from the MediaFire link provided above, go to the Unity folder in the root directory of the project repository and delete the existing CV Ball Tracking Game Folder, and place the new downloaded folder there.
  • You can also choose to place the CV Ball Tracking Game Folder in another location in your computer instead of putting it in the folder mentioned in the previous step but make sure you can easily access it as you'll need it in the next step.
  • Open Unity, click on existing project, and select the CV Ball Tracking Game folder that you downloaded.
  • Install the LeanTween asset from the asset store from the link above.
  • Open a Command Prompt/Terminal in the Root Directory of the Project.
  • Type the following command in the terminal to run the Python script.
python CVBallTrackingGame.py
  • Simultaneously, click on the run button in the opened Unity project.

  • get a red ball to use in the game.

  • Enjoying playing the game!

About

⚡A computer vision game in which the user is able to a tumble blocks using a ball tracked in real-time

Resources

Stars

Watchers

Forks

Releases

No releases published