From 0f185fc51ef0c32596af6a492b2ba47ff574787b Mon Sep 17 00:00:00 2001
From: Preethi Satish <pr2satish@gmail.com>
Date: Fri, 21 Jun 2024 00:10:48 -0700
Subject: [PATCH] made threshold vals more clear

---
 .../__pycache__/detector.cpython-38.pyc       | Bin 2047 -> 2245 bytes
 src/main/python/detector.py                   |  12 ++++--------
 src/main/python/test.py                       |   5 ++++-
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/main/python/__pycache__/detector.cpython-38.pyc b/src/main/python/__pycache__/detector.cpython-38.pyc
index 802fe1f19955dbc7531ff255f48143741c7c89f2..66288f96cbf7123d617ac11f619a3d00ec23daa1 100644
GIT binary patch
delta 836
zcmZuv&1(}u6wmB#lWo3>rL|CDDD`8tRmed~DZOYZ6-l7g%Ob3k-AQ)o?o4<y+maH<
zK@XmUus0FZi{RP6!Ly$CF8E*QOxmU>zTrJ)-pB8~ncw_wd|RkLuhq&0CD!e<_v_lE
zzKYo7-iu}1t?d_r`Jnu|5R_jTZaqLp1*bCkygvE<e$hegF9iqXmY{JDY*h|+Hb#fz
z6}1(H#zSWdkEx`-<Z$2fA{I%{^DP~@5WSyM`bep$D<caZ(Fl!<k@?9~z0lducIVmN
zHkKUA5U2=w9N^PPhB)Dj`yudz;wT|~itmVs^<%m@_CvxLjW=)~$WZtsrjD-nff7kE
z!QF@v7~+J8;|*NK|A<c*76a->y`joII%w}d-NPD%06rmcN^y?^j`=Bt2kBry0e5-I
z0x<&`UjhP^DKN2p+3@c%XH#x%b|dLHMsE5it-KVmL&Eyhv0z@khufH4!kgB+HPzai
zy@gv3qkedGRy^F)M5t2Gl;+i7N<arR=&JIZGh=1%41wNeb#u2e1EWFKF*~T5eK4P_
z>F&@_#<hLUBu_!)$h+WK$I4m7x@%UJs@ay+Ld~zomWPT}9a+kL%)Km50amhy#TGvQ
z9Md9Y^2P<A7YUDXNq4e0MK`YKxc&pMrjtr6AfO0@>-uDMIgjC%j$VPyZV4q7SXL^u
z%QkG&E-kK1y-ox4Ou3a18Rl~=O$I|)%i1OP;D++Ux;DD}f4I55lkgyo=`K<kVo@0z
P=~dO%YNDoX8J6(}pU2Ny

delta 636
zcmZvZL2uJA6vyM(ZQV9WThUbr21A1ig&_`=xS??wG@yw}Eof3SDGN#3MoJT8yOqXe
z2N3tlcMuYno%sNq_!7Qw=EgSwzpQ8+u$7;l{rvv#@A!M?cguNY+YLjHet$WAy0vz;
z(Q3VSyi@h<nEFm!_gh0FZp6*^M%;X7`t2A^4A)wJykq{%*WW&M&(Vu>!$pelB%3mj
zVhzdA`2MyIxe3zfZRa2nNhAvPAPCYt6+sYT$ZQ6dzfkW?m;!&s6NA<Dwo4R_Rs&T_
z^KqEZ5@jEbj)Iro_{qc@9Udshdp7hg*DhvFUFElCEIj2=m?c5F2z6Oq%vr+cMHX+o
z=~K+oP*z-e8ZnUHF%0_Gt(;<xK1hZ4@tm*ZZ8AcR<mCA-bYNX*L!%-W#gcJ_f`4`8
z4{{IpdbYGG1GM$^aV0=i2db{iFV&N3DR5IZYJ*!BKMGQ%nbt-yNO_PKBJt#L%|Ejt
ze+6(?L)G#)Wcq&W2CT^IqR7}DWG}_a2oxFBxTZf20W~S6q}wld-3|j!iY!7gSCxFZ
zcyoHupejN(O9X>g^KC94(&15C$E*X`1-Jl^{9jW=A1#V_nI-#3pWs(DD1vDLNgK6I
Kf(RuhG5-KTWs8CU

diff --git a/src/main/python/detector.py b/src/main/python/detector.py
index 4115374..caedfd9 100644
--- a/src/main/python/detector.py
+++ b/src/main/python/detector.py
@@ -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])
@@ -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:
diff --git a/src/main/python/test.py b/src/main/python/test.py
index 320ee2f..1404813 100644
--- a/src/main/python/test.py
+++ b/src/main/python/test.py
@@ -7,6 +7,9 @@
 cap = cv2.VideoCapture(0)
 counter = 0
 
+LOW_THRESHOLD = 110
+HIGH_THRESHOLD = 255
+
 while(True):
 
     ret, frame = cap.read()
@@ -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):