I have developed a Python program that allows you to control the OS mouse cursor hands-free using a standard USB camera. This tool tracks the user’s head movement and translates it into mouse coordinates in real-time.
The complete source code is available on GitHub: GitHub Repository: head-mouse-controller-
Overview
The program utilizes MediaPipe for facial landmark tracking. Specifically, it captures the coordinates of the nose tip from the video feed and calculates the displacement between frames. This displacement is then scaled according to the screen resolution to move the cursor.
Core Features
- Real-time Tracking: Uses MediaPipe’s Face Mesh to track the nose tip accurately.
- Cursor Smoothing: Implements Exponential Moving Average (EMA) to filter out minor camera jitters and stabilize the cursor movement.
- FailSafe Mechanism: Moving the cursor to any of the four extreme corners of the screen will immediately terminate the program for safety.
- Easy Setup: Includes a run.bat file for Windows environments to automate the installation of requirements and execution.
Environment Requirements
- Python 3.9 or higher
- A connected USB (Web) camera
- Required Libraries:
opencv-python,mediapipe==0.10.14,pyautogui,numpy
How to Use
- Clone or download the repository from GitHub.
- Install the required packages via standard pip:
pip install -r requirements.txt - Run the main script:
python main.py(Note: Windows users can simply execute the provided run.bat)
Once running, a video feed window will appear. The cursor will automatically follow your head movements as long as your face is visible. To exit the program, you can either press the q key while the video window is focused or trigger the FailSafe by physically moving your mouse to a screen corner.
If you are interested in testing or modifying the code, please visit the repository linked above. Future development may include adding click functionality via facial gestures.