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.
- 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.
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# 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.txtThe project includes the OpenCV DNN Face Detector based on a Caffe model.
These files are already provided in the models/ folder:
deploy.prototxtres10_300x300_ssd_iter_140000.caffemodel
No additional downloads are required.
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.
- Loads OpenCV DNN face detection model.
- Captures webcam frames and detects face positions.
- Defines a central control zone.
- Detects movement โ triggers directional key events using PyAutoGUI.
- Logs activity and displays FPS overlay.
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:
- GUI frontend (PyQt5).
- Multi-user support.
- Game scoring/session logging.
- REST API integration.
This project is licensed under the MIT License.
Heleena Robert
GitHub

