This project demonstrates how to control screen brightness based on hand gestures using Python. It utilizes OpenCV for image processing, Mediapipe for hand detection, and a PowerShell script to adjust screen brightness on Windows.
- Detects hand gestures using the webcam.
- Adjusts screen brightness based on the openness of the hand.
- Reduces brightness when the hand is closed and increases it when the hand is open.
- Python: Ensure Python is installed on your system.
- PowerShell: For running the PowerShell script that adjusts screen brightness.
You need to install the following Python libraries:
pip install opencv-python mediapipe
You need to create a PowerShell script to control the screen brightness. Follow these steps:
-
Open a Text Editor: Use any text editor like Notepad or Visual Studio Code.
-
Create a New File: Name it
set_brightness.ps1
. -
Add the PowerShell Script Code: Copy and paste the following code into the file:
param (
[int]$brightness
)
# Ensure brightness is between 0 and 100
$brightness = [math]::Max(0, [math]::Min(100, $brightness))
# Adjust the screen brightness
(Get-WmiObject -Namespace root/wmi -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1, $brightness)
- Save the File: Save this file in the same directory as your Python script.
If you encounter issues running the PowerShell script, you might need to adjust the execution policy:
-
Open PowerShell as Administrator: Right-click the PowerShell icon and select "Run as Administrator".
-
Set Execution Policy: Run the following command:
Set-ExecutionPolicy RemoteSigned
Confirm the change by typing Y and pressing Enter.
Ensure that your webcam is properly connected and accessible. The script requires webcam access to detect hand gestures.
-
Navigate to the directory containing your Python script and the
set_brightness.ps1
file. -
Run the Python script using:
python BrightHandControl.py
-
Control Brightness with Hand Gestures:
- Closed Hand: Screen brightness will decrease.
- Open Hand: Screen brightness will increase.
-
Exit: Press the 'q' key while the script window is active to stop the program.
- Hand Detection: Uses Mediapipe to detect hand landmarks and gestures.
- Brightness Adjustment: Calls a PowerShell script to adjust the brightness based on the detected hand gesture.
If you have any questions or need further assistance, feel free to contact us at my email : faezeh.darbeheshti@gmail.com .