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

Commit

Permalink
Changed min and max color to avg color calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelLucas committed Nov 1, 2018
1 parent 79377c7 commit c901d95
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
18 changes: 17 additions & 1 deletion color_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,25 @@ def captureCamera(left=False):
[hsvRoi[:, :, 0].min(), hsvRoi[:, :, 1].min(), hsvRoi[:, :, 2].min()])
upper = np.array(
[hsvRoi[:, :, 0].max(), hsvRoi[:, :, 1].max(), hsvRoi[:, :, 2].max()])
h = hsvRoi[:, :, 0]
s = hsvRoi[:, :, 1]
v = hsvRoi[:, :, 2]
hAverage = np.average(h)
sAverage = np.average(s)
vAverage = np.average(v)

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 [lower, upper]
return np.array([[hAverage, sAverage, vAverage], [hMaxSensibility, sMaxSensibility, vMaxSensibility]])


def display_result(roi):
Expand Down
6 changes: 3 additions & 3 deletions hand_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def main():

if key == ord('v'):
try:
lower_color, upper_color = cc.captureCamera(args.left)
avg_color, max_sensibility = cc.captureCamera(args.left)
vd.start(
lower_color,
upper_color,
avg_color,
max_sensibility,
video=not args.shot,
path=args.input,
left=args.left)
Expand Down
22 changes: 19 additions & 3 deletions video_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import traceback


def start(lower_bound_color,
upper_bound_color,
def start(avg_color,
max_sensibility,
video=True,
path=None,
left=False):
Expand All @@ -28,6 +28,22 @@ def start(lower_bound_color,
left : bool, optional
Set the ROI on the left side of the screen
"""

# change this value to better adapt to environment light
hSensibility = 3
sSensibility = 15
vSensibility = 15

if hSensibility > max_sensibility[0]:
hSensibility = max_sensibility[0]
if sSensibility > max_sensibility[1]:
sSensibility = max_sensibility[1]
if vSensibility > max_sensibility[2]:
vSensibility = max_sensibility[2]

lower_bound_color = np.array([avg_color[0] - hSensibility, avg_color[1] - sSensibility, avg_color[2] - vSensibility])
upper_bound_color = np.array([avg_color[0] + hSensibility, avg_color[1] + sSensibility, avg_color[2] + vSensibility])

if path != None:
frame = cv2.imread(path)
hand_detection(frame, lower_bound_color, upper_bound_color, left)
Expand Down Expand Up @@ -147,7 +163,7 @@ def analyse_defects(cnt, roi):
def analyse_contours(frame, cnt, l):
"""
Writes to the image the signal of the hand.
The hand signals can be the numbers from 0 to 5, the ‘ok’ signal, and the all right symbol.
The hand signals can be the numbers from 0 to 5, the 'ok' signal, and the 'all right' symbol.
The signals is first sorted by the number of convexity defects. Then, if the number of convexity defects is 1, 2, or 3, the area ratio is to be analysed.
Parameters
----------
Expand Down

0 comments on commit c901d95

Please sign in to comment.