Skip to content

HeleenaRobert/face-game-controller-opencv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Face-Controlled Game Controller using OpenCV

Banner

Python OpenCV License Made with Love By HeleenaRobert

An AI-powered Python application that enables hands-free game control using real-time face detection via webcam.
Built with OpenCV DNN for detection and PyAutoGUI for keyboard automation, this project brings accessibility and interactivity to gaming and beyond.


โœจ Features

  • Real-time face detection using OpenCV DNN.
  • Direction-based key control (โฌ…๏ธ โฌ†๏ธ โžก๏ธ โฌ‡๏ธ) mapped to head movement.
  • FPS monitoring for performance tracking.
  • Modular and extensible codebase.
  • One-click game start when face enters control zone.

๐Ÿ“‚ Project Structure

face-game-controller/
โ”‚
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ banner.png                                     # Project banner
โ”‚   โ””โ”€โ”€ sample_output.png            
โ”‚
โ”œโ”€โ”€ models/                                            # Pretrained Caffe model
โ”‚   โ”œโ”€โ”€ deploy.prototxt
โ”‚   โ””โ”€โ”€ res10_300x300_ssd_iter_140000.caffemodel
โ”‚ 
โ”œโ”€โ”€ utils/
โ”‚   โ”œโ”€โ”€ config.py                                      # Configuration (model paths) 
โ”‚   โ”œโ”€โ”€ controller.py                                  # Movement control (PyAutoGUI) 
โ”‚   โ””โ”€โ”€ face_detection.py                              # Face detection logic (OpenCV DNN)
โ”‚ 
โ”œโ”€โ”€ main.py
โ”‚ 
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ requirements.txt                                   # Dependencies
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

โš™๏ธ Installation

# Clone repository
git clone https://github.com/HeleenaRobert/face-game-controller-opencv.git
cd face-game-controller-opencv

# Create virtual environment (optional)
python -m venv venv
source venv/bin/activate    # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

๐Ÿ“ฆ Model Files

The project includes the OpenCV DNN Face Detector based on a Caffe model.
These files are already provided in the models/ folder:

  • deploy.prototxt
  • res10_300x300_ssd_iter_140000.caffemodel

No additional downloads are required.


๐Ÿš€ Usage

python main.py
  • Align your face in the control zone to start.
  • Move your head left / right / up / down โ†’ triggers arrow key events.
  • Press ESC to exit.

๐ŸŽฏ How It Works

  1. Loads OpenCV DNN face detection model.
  2. Captures webcam frames and detects face positions.
  3. Defines a central control zone.
  4. Detects movement โ†’ triggers directional key events using PyAutoGUI.
  5. Logs activity and displays FPS overlay.

๐Ÿ“Š Sample Output

When running the program, the webcam feed will open with:

  • A green bounding box highlighting the detected face.
  • A red central control zone where the face must align to start the game.
  • FPS counter shown on top-left.
  • Head movements mapped to key events:
Face Position Triggered Action
Face inside control zone Game starts (auto click)
Move head left โฌ…๏ธ Presses Left Arrow
Move head right โžก๏ธ Presses Right Arrow
Move head up โฌ†๏ธ Presses Up Arrow
Move head down โฌ‡๏ธ Presses Down Arrow

Example annotated frame:

Sample Output

AI Generated


๐Ÿ› ๏ธ Future Improvements

  • GUI frontend (PyQt5).
  • Multi-user support.
  • Game scoring/session logging.
  • REST API integration.

๐Ÿ“ License

This project is licensed under the MIT License.


๐Ÿ‘ฉโ€๐Ÿ’ป Author

Heleena Robert
GitHub

About

๐ŸŽฎ Hands-free game controller using OpenCV DNN face detection + PyAutoGUI for directional control.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages