Skip to content

Commit

Permalink
made threshold vals more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
pr2satish committed Jun 21, 2024
1 parent 613dfe9 commit 0f185fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Binary file modified src/main/python/__pycache__/detector.cpython-38.pyc
Binary file not shown.
12 changes: 4 additions & 8 deletions src/main/python/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

# define orange hsv values (opencv range is h:0-180, s:0-255, v:0-255)
# NOTE: BELOW VALS REPRESENT RED ACTUALLY BC I ONLY HAD A RED SPONGE TO USE
LOWER_ORANGE_HSV = np.array([3, 80, 80])
UPPER_ORANGE_HSV = np.array([6, 255, 255])

LOW_THRESHOLD = 110
HIGH_THRESHOLD = 255

# LOWER_ORANGE_HSV = np.array([3, 80, 80])
# UPPER_ORANGE_HSV = np.array([6, 255, 255])

# orange hsv values
# LOWER_ORANGE_HSV = np.array([3, 80, 80])
Expand All @@ -28,11 +24,11 @@ class Detector:
def __init__(self):
pass

def detectOrange(self, grayscale_image, threshold):
def detectOrange(self, grayscale_image, low_threshold, high_threshold):
"""NOTE: to threshold with monochrome image (single-channel, grayscale) to create a binary mask,
can specify a SINGLE scalar value for lower/upper bounds
returns: binary image (single-channel, 8-bit)"""
return cv2.inRange(grayscale_image, LOW_THRESHOLD, HIGH_THRESHOLD)
return cv2.inRange(grayscale_image, low_threshold, high_threshold)
#return np.where(grayscale_image > threshold, 255, 0).astype(np.uint8)

def find_largest_orange_contour(self, orange_mask: np.ndarray) -> np.ndarray:
Expand Down
5 changes: 4 additions & 1 deletion src/main/python/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
cap = cv2.VideoCapture(0)
counter = 0

LOW_THRESHOLD = 110
HIGH_THRESHOLD = 255

while(True):

ret, frame = cap.read()
Expand All @@ -24,7 +27,7 @@
# convert tuple from (height, width, # of channels) to just (height, width)
frame_single_channel = frame[:,:,0]

orange_mask = d.detectOrange(frame_single_channel, threshold=100)
orange_mask = d.detectOrange(frame_single_channel, LOW_THRESHOLD, HIGH_THRESHOLD)
contour = d.find_largest_orange_contour(orange_mask)
#cv2.drawContours(frame, contour, 0, [255, 0, 0], 2)
if contour is not None and d.contour_is_note(contour):
Expand Down

0 comments on commit 0f185fc

Please sign in to comment.