diff --git a/color_calculator.py b/color_calculator.py index 59a2c53..5cb684e 100644 --- a/color_calculator.py +++ b/color_calculator.py @@ -7,8 +7,8 @@ def captureCamera(left=False): """ Creates a color bound based on a ROI - It analyses the blue square and calculates the maximum and minimum HSV values inside the square. - Those maximum and minimum will be the color bound used to detect the hand. + It analyses the blue square and calculates the maximum, minimum and average HSV values inside the square. + Those maximum and minimum values will be used to determine the maximum sensibility possible, and the average will be the color bound used to detect the hand. Parameters ---------- left : bool, optional @@ -75,12 +75,6 @@ def captureCamera(left=False): hMaxSensibility = max(abs(lower[0] - hAverage), abs(upper[0] - hAverage)) sMaxSensibility = max(abs(lower[1] - sAverage), abs(upper[1] - sAverage)) vMaxSensibility = max(abs(lower[2] - vAverage), abs(upper[2] - vAverage)) - print("average = ", np.array([hAverage, sAverage, vAverage])) - print("min = ", lower) - print("max = ", upper) - print("hMaxSensibility = ", hMaxSensibility) - print("sMaxSensibility = ", sMaxSensibility) - print("vMaxSensibility = ", vMaxSensibility) cv2.destroyAllWindows() return np.array([[hAverage, sAverage, vAverage], [hMaxSensibility, sMaxSensibility, vMaxSensibility]]) diff --git a/video_detection.py b/video_detection.py index 8543402..6d6f7b6 100644 --- a/video_detection.py +++ b/video_detection.py @@ -11,6 +11,22 @@ def nothing(x): def apply_sensibility(avg_color, newHSens, newSSens, newVSens, maxSensibility): + """ + Applies sensibility values for each value of HSV, taking into account the maximum sensibility possible. + It analyses the parameters and executes the hand detection accordingly. + Parameters + ---------- + avg_color : array + The average of HSV values to be detected + newHSens : int + Percentage of sensibility to apply to Hue + newSSens : int + Percentage of sensibility to apply to Saturation + newVSens : int + Percentage of sensibility to apply to Value + maxSensibility : array + The maximum error margin of HSV values to be detected + """ hSens = (newHSens * maxSensibility[0]) / 100 SSens = (newSSens * maxSensibility[1]) / 100 VSens = (newVSens * maxSensibility[2]) / 100 @@ -29,10 +45,10 @@ def start(avg_color, It analyses the parameters and executes the hand detection accordingly. Parameters ---------- - lower_bound_color : array - The min of HSV values to be detected - upper_bound_color : array - The max of HSV values to be detected + avg_color : array + The average of HSV values to be detected + max_sensibility : array + The maximum error margin of HSV values to be detected video : bool, optional False if single image True if video stream @@ -43,9 +59,9 @@ def start(avg_color, """ # change this value to better adapt to environment light (percentage values) - hSensibility = 90 - sSensibility = 80 - vSensibility = 80 + hSensibility = 100 + sSensibility = 100 + vSensibility = 100 apply_sensibility(avg_color, hSensibility, sSensibility, vSensibility, max_sensibility) @@ -66,10 +82,12 @@ def start(avg_color, _, frame = video_capture.read() frame = cv2.flip(frame, 1) + # get values from trackbar newHSens = cv2.getTrackbarPos('HSensb', 'Hand Detection') newSSens = cv2.getTrackbarPos('SSensb', 'Hand Detection') newVSens = cv2.getTrackbarPos('VSensb', 'Hand Detection') + # and apply the new sensibility values lower_bound_color, upper_bound_color = apply_sensibility(avg_color, newHSens, newSSens, newVSens, max_sensibility) hand_detection(frame, lower_bound_color, upper_bound_color,