-
Notifications
You must be signed in to change notification settings - Fork 55
Add/brightness control #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Avdhesh-Varshney
merged 7 commits into
Code-A2Z:main
from
that-ar-guy:add/brightness-control
Jan 26, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
022367a
index updated/template created
that-ar-guy 0c2a50e
image/ss to be added
that-ar-guy 4235ef8
screenshots added
that-ar-guy 19db65e
position corrected
that-ar-guy 39609ca
corrected link to notebook
that-ar-guy 19c1169
code explaination updated
that-ar-guy 244f14b
extra imgs/videos removed
that-ar-guy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| # 📜 Brightness control | ||
| <div align="center"> | ||
| <img src="https://user-images.githubusercontent.com/59369441/116009572-1542a280-a638-11eb-9d94-2a2d38b856a5.PNG" /> | ||
| </div> | ||
|
|
||
| ## 🎯 AIM | ||
| To develop a real-time brightness control system using hand gestures, leveraging OpenCV and MediaPipe for hand detection and brightness adjustment. | ||
|
|
||
|
|
||
| ## 📊 DATASET LINK | ||
| No dataset used | ||
|
|
||
| ## 📓 NOTEBOOK LINK | ||
| <!-- Provide the link to the notebook where you solved the project. It must be only Kaggle public notebook link. --> | ||
| [https://drive.google.com/file/d/1q7kraajGykfc2Kb6-84dCOjkrDGhIQcy/view?usp=sharing](https://drive.google.com/file/d/1q7kraajGykfc2Kb6-84dCOjkrDGhIQcy/view?usp=sharing) | ||
|
|
||
|
|
||
| ## ⚙️ TECH STACK | ||
|
|
||
| | **Category** | **Technologies** | | ||
| |--------------------------|---------------------------------------------| | ||
| | **Languages** | Python | | ||
| | **Libraries/Frameworks** | OpenCV, NumPy, MediaPipe, cvzone | | ||
| | **Tools** | Jupyter Notebook, Local Python IDE | | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ## 📝 DESCRIPTION | ||
| !!! info "What is the requirement of the project?" | ||
| - The project requires a webcam to capture real-time video and detect hand gestures for brightness control. | ||
|
|
||
| ??? info "How is it beneficial and used?" | ||
| - Allows users to control screen brightness without physical touch, making it useful for touchless interfaces. | ||
| - Ideal for applications in smart home systems and assistive technologies. | ||
|
|
||
| ??? info "How did you start approaching this project? (Initial thoughts and planning)" | ||
| - Identified the need for a touchless brightness control system. | ||
| - Selected OpenCV for video processing and MediaPipe for efficient hand tracking. | ||
| - Developed a prototype to calculate brightness based on hand distance. | ||
|
|
||
| ??? info "Mention any additional resources used (blogs, books, chapters, articles, research papers, etc.)." | ||
| - OpenCV documentation for video processing. | ||
| - MediaPipe's official guide for hand tracking. | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ## 🔍 EXPLANATION | ||
|
|
||
| ### 🧩 DETAILS OF THE DIFFERENT FEATURES | ||
|
|
||
| #### 🛠 Developed Features | ||
|
|
||
| | Feature Name | Description | Reason | | ||
| |--------------|-------------|----------| | ||
| | Hand Detection | Detects hand gestures in real-time | To control brightness with gestures | | ||
| | Distance Calculation | Calculates distance between fingers | To adjust brightness dynamically | | ||
| | Brightness Mapping | Maps hand distance to brightness levels | Ensures smooth adjustment of brightness | | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ### 🛤 PROJECT WORKFLOW | ||
|
|
||
| !!! success "Project workflow" | ||
|
|
||
| ``` mermaid | ||
| graph LR | ||
| A[Start] --> B[Initialize Webcam]; | ||
| B --> C[Detect Hand Gestures]; | ||
| C --> D[Calculate Distance]; | ||
| D --> E[Adjust Brightness]; | ||
| E --> F[Display Output]; | ||
| ``` | ||
|
|
||
| === "Step 1" | ||
| - Initialize the webcam using OpenCV. | ||
|
|
||
|
|
||
| === "Step 2" | ||
| - Use MediaPipe to detect hands in the video feed. | ||
|
|
||
| === "Step 3" | ||
| - Calculate the distance between two fingers (e.g., thumb and index). | ||
|
|
||
| === "Step 4" | ||
| - Map the distance to a brightness range. | ||
|
|
||
| === "Step 5" | ||
| - Display the adjusted brightness on the video feed. | ||
|
|
||
| --- | ||
|
|
||
| ### 🖥 CODE EXPLANATION | ||
|
|
||
| === "Section 1: Webcam Initialization" | ||
| - The program begins by setting up the webcam to capture frames with a resolution of 640x480 pixels. This ensures consistent processing and visualization of the video stream. | ||
|
|
||
| ```python | ||
| cap = cv2.VideoCapture(0) | ||
| cap.set(3, 640) # Set width | ||
| cap.set(4, 480) # Set height | ||
| ``` | ||
|
|
||
| === "Section 2: Hand Detection and Brightness Control" | ||
| - Using the `HandDetector` from `cvzone`, the program tracks one hand (maxHands=1). The brightness of the video frame is dynamically adjusted based on the distance between the thumb and index finger. | ||
|
|
||
| ```python | ||
| detector = HandDetector(detectionCon=0.8, maxHands=1) | ||
| brightness = 1.0 # Default brightness level | ||
| ``` | ||
|
|
||
| - The HandDetector detects hand landmarks in each frame with a confidence threshold of 0.8. The initial brightness is set to 1.0 (normal). | ||
|
|
||
| ```python | ||
| hands, img = detector.findHands(frame, flipType=False) | ||
|
|
||
| if hands: | ||
| hand = hands[0] | ||
| lm_list = hand['lmList'] | ||
| if len(lm_list) > 8: | ||
| thumb_tip = lm_list[4] | ||
| index_tip = lm_list[8] | ||
| distance = int(((thumb_tip[0] - index_tip[0]) ** 2 + (thumb_tip[1] - index_tip[1]) ** 2) ** 0.5) | ||
| brightness = np.interp(distance, [20, 200], [0, 1]) | ||
| ``` | ||
|
|
||
| - The program calculates the distance between the thumb tip (`lmList[4]`) and index finger tip (`lmList[8]`). This distance is mapped to a brightness range of 0 to 1 using np.interp. | ||
|
|
||
| === "Section 3: Brightness Adjustment and Display " | ||
|
|
||
| - The captured frame's brightness is modified by scaling the value (V) channel in the HSV color space according to the calculated brightness level. | ||
|
|
||
| ```python | ||
| hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) | ||
| hsv[..., 2] = np.clip(hsv[..., 2] * brightness, 0, 255).astype(np.uint8) | ||
| frame_bright = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) | ||
| cv2.imshow("Brightness Controller", frame_bright) | ||
| ``` | ||
|
|
||
| - This technique ensures smooth, real-time brightness adjustments based on the user's hand gestures. The output frame is displayed with the adjusted brightness level. | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ### ⚖️ PROJECT TRADE-OFFS AND SOLUTIONS | ||
|
|
||
|
|
||
| === "Trade Off 1" | ||
| - Real-time processing vs. computational efficiency: Optimized hand detection by limiting the maximum number of detectable hands to 1. | ||
|
|
||
|
|
||
| === "Trade Off 2" | ||
| - Precision in brightness control vs. usability: Adjusted mapping function to ensure smooth transitions. | ||
|
|
||
| --- | ||
|
|
||
| ## 🖼 SCREENSHOTS | ||
| ??? tip "Working of the model" | ||
|
|
||
| === "Image Topic" | ||
| <img width="485" alt="image" src="https://github.com/user-attachments/assets/4b7ea465-a916-4592-9026-9bfa41711763" /> | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
| ## ✅ CONCLUSION | ||
|
|
||
| ### 🔑 KEY LEARNINGS | ||
| !!! tip "Insights gained from the data" | ||
| - Improved understanding of real-time video processing. | ||
| - Learned to integrate gesture detection with hardware functionalities. | ||
|
|
||
| ??? tip "Improvements in understanding machine learning concepts" | ||
| - Gained insights into MediaPipe's efficient hand detection algorithms. | ||
|
|
||
| --- | ||
|
|
||
| ### 🌍 USE CASES | ||
| === "Smart Homes" | ||
| - Touchless brightness control for smart home displays. | ||
|
|
||
| === "Assistive Technologies" | ||
| - Brightness adjustment for users with limited mobility. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.