Gesture Volume Control is an exciting project that allows you to change the volume of your system by using hand gestures. The project utilizes computer vision and audio control libraries to achieve this functionality. With Gesture Volume Control, you can have a more interactive and intuitive way to manage audio levels on your system.
Gesture Volume Control is a Python-based project that uses OpenCV and Mediapipe to track hand movements and recognize hand landmarks. By measuring the distance between the index finger and thumb, the project calculates the desired volume level and adjusts it accordingly using the pycaw library. This project provides a creative way to interact with your computer's audio system and showcases the potential of computer vision in real-world applications.
Before running the project, ensure you have the following libraries installed:
- opencv-contrib-python 4.7.0.72
- mediapipe 0.9.1.0
- pycaw 20220416
- comtypes (a dependency for pycaw)
This module is responsible for tracking hand movements and identifying 21 hand landmarks defined by Google in Mediapipe.
This function takes a BGR image as input and converts it to RGB to highlight the 21 hand landmarks along with the connections between them.
The findPosition
function is used to get the position of a particular landmark on the hand and highlights it by drawing a circle around it.
This module is the core of the project and executes the main functionality. It first detects hand movements using the HandTrackingModule. The user needs to specify the landmark numbers for the index finger (8) and thumb (4) provided by Mediapipe.
The module calculates the distance between the index finger and thumb using the hypot
method from the math
module. It also calculates the midpoint of the line joining these two landmarks, which changes its color below a certain range.
To implement the volume control, the pycaw
library is used. The necessary audio initialization and volume control methods are performed on the system's default audio output. The GetVolumeRange
method is used to determine the range of volume levels for proper conversion.
To display the volume bar on the screen, the rectangle
method from the OpenCV library is used with appropriate dimensions.
-
Clone this repository:
git clone https://github.com/BhardwajArjit/Gesture-Volume-Control.git
-
Install the required libraries from the
requirements.txt
file:pip install -r requirements.txt
-
Import the necessary modules and functions into your main Python script.
-
Initialize the hand tracking and volume control functionalities.
-
Capture the video feed from the camera or use pre-recorded video.
-
Continuously track the hand landmarks and calculate the distance between the index finger and thumb.
-
Determine the desired volume level based on the calculated distance and apply the volume changes using pycaw.
-
Display the volume bar on the screen to provide visual feedback to the user.
- Ensure that the camera or video feed has good lighting and clear visibility of the hand for accurate hand tracking.
- Calibrate the distance range between the index finger and thumb for volume control according to your preference and comfort.
- Handle any exceptions or errors that may occur during the execution to provide a smooth user experience.
This project is licensed under the MIT License - see the LICENSE file for details.