Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
Added more comments and removed debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelLucas committed Nov 2, 2018
1 parent 918a0b7 commit 96e7f81
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
10 changes: 2 additions & 8 deletions color_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]])
Expand Down
32 changes: 25 additions & 7 deletions video_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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,
Expand Down

0 comments on commit 96e7f81

Please sign in to comment.