Skip to content

Commit b2bca9e

Browse files
authored
HSV filter tool
interactive HSV filter tool that allows users to select HSV color ranges from an image using trackbars, and print hue, saturation, and value ranges.Useful for trying to find the right HSV range to use when doing basic color filtration
1 parent 22c4c01 commit b2bca9e

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

computer_vision/hsv_threshold

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
"""
22
HSV Filter Tool
33

4-
This module allows the user to interactively select an HSV color range
5-
from an image using trackbars and outputs the selected HSV values.
4+
This file lets the user to interactively select an HSV color range
5+
from an image using trackbars and outputs the selected HSV range.
66

7-
Dependencies:
8-
- OpenCV (cv2)
9-
- NumPy
10-
11-
Usage:
127
1. Set `IMAGE_PATH` to your image file.
138
2. Run the script.
149
3. Adjust the trackbars to select the desired HSV range.
15-
4. Press Enter to print the HSV lower and upper bounds.
10+
4. Enter to print the HSV lower and upper bounds.
1611
"""
1712

1813
import cv2
1914
import numpy as np
2015

16+
#Example Path
2117
IMAGE_PATH = r"C:\Users\username\New folder\your_image.png"
2218

2319

24-
def load_image(path: str) -> np.ndarray:
20+
def load_image(path):
2521
"""
2622
Load an image from the specified path.
2723

@@ -46,7 +42,7 @@ def load_image(path: str) -> np.ndarray:
4642
return image
4743

4844

49-
def create_hsv_trackbars(window_name: str) -> None:
45+
def create_hsv_trackbars(window_name):
5046
"""
5147
Create HSV trackbars for filtering.
5248

@@ -63,7 +59,7 @@ def create_hsv_trackbars(window_name: str) -> None:
6359
cv2.createTrackbar("V Upper", window_name, 255, 255, lambda x: None)
6460

6561

66-
def get_hsv_bounds(window_name: str) -> tuple[np.ndarray, np.ndarray]:
62+
def get_hsv_bounds(window_name):
6763
"""
6864
Read the HSV lower and upper bounds from the trackbars.
6965

@@ -90,7 +86,7 @@ def get_hsv_bounds(window_name: str) -> tuple[np.ndarray, np.ndarray]:
9086
return lower_bound, upper_bound
9187

9288

93-
def main() -> None:
89+
def main():
9490
"""
9591
Main function to run the HSV filter tool.
9692

0 commit comments

Comments
 (0)