Skip to content

Commit

Permalink
Better variable naming for debugging - Fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinao committed Aug 28, 2016
1 parent 29a25c2 commit 27f92b9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 44 deletions.
21 changes: 17 additions & 4 deletions Motion/config.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
config = {
# When on-board camera is used, not a USB one
'piCamera': {
'useCameraBoard': False,
'framerate': 16,
'resolution': (320, 240)
},
# Avoid doing things when nothing happens
'timeToSleepWhenNoMovement': 1,
# No movement but maybe it will start again
'timeToWaitWhenNoMovementBeforeSleep': 5,
# How much difference between frame there must be for it to be called movement
'frameDifferenceRatioForMovement': 1,
'hand': {
'hsv_min_blue': [0, 0, 0],
'hsv_max_blue': [255, 255, 255],
'hsv_dec_blue': [255, 55, 32],
'hsv_inc_blue': [255, 255, 255],
# Min/Max HSV values to get the palm
'hsv_palm_min': [0, 0, 0],
'hsv_palm_max': [255, 255, 255],
# For the hand color range we will take the HSV center point of the palm and apply these inc/dec
'hsv_hand_dec': [255, 55, 32],
'hsv_hand_inc': [255, 255, 255],
# Hand not found anymore, do not revert to palm detection before x seconds
'timeToKeepSearchingHandWhenLostTracking': 1,
# Minimum size of hand to avoid false detection
'minimumHeight': 80,
'maximumHeight': 350,
'minimumWidth': 80,
'maximumWidth': 320,
# Size of thumbs compared to the hand
'thumbsDetectMinimumHeightRatio': 0.12,
# Defect between each finger max x/y distance between each other
'MaximumYDistanceBetweenDefectForPalmInHandRatio': 0.08,
'MaximumXDistanceBetweenDefectForPalmInHandRatio': 0.2,
# How much your hand much move to be a slide gesture
'minimumMoveHandForSlide': 150,
# How fast it must be for it to be a slide gesture
'maximumTimeHandForSlide': 0.5,
# How long after a slide gesture you can do another one
'delayAfterHandSlide': 0.5
}
}
5 changes: 3 additions & 2 deletions Motion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def SendGesture(gesture):
try:
requests.get("http://localhost:3000/motion/gesture", params=json.dumps(gesture.properties))
except Exception as ex:
print("Could not send gesture: ")
print("Could not send gesture: " + str(ex))

def ManageCommands(motion):
global take_photo
Expand All @@ -40,7 +40,8 @@ def ManageMotion():
time.sleep(config['timeToSleepWhenNoMovement'])

gesture = motion.GetGesture()

if gesture.properties['palm']:
print("PALM")
threading.Thread(target=SendGesture, args=(gesture,)).start()

motion.Dispose()
Expand Down
10 changes: 5 additions & 5 deletions Motion/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def GetInformationOnNextFrame(self):
self.timeLastMotion = time.time()

def TryToTrackHand(self):
lower_blue_brightness = 255
lower_blue_brightness = config['hand']['hsv_palm_max'][2]
search_hand = Gesture()

while lower_blue_brightness > 15:
# define range of blue color in HSV
lower_blue = np.array([config['hand']['hsv_lower_blue'][0], config['hand']['hsv_lower_blue'][1], lower_blue_brightness])
upper_blue = np.array([config['hand']['hsv_upper_blue'][0], config['hand']['hsv_upper_blue'][1], 255])
lower_blue = np.array([config['hand']['hsv_palm_min'][0], config['hand']['hsv_palm_min'][1], lower_blue_brightness])
upper_blue = np.array([config['hand']['hsv_palm_max'][0], config['hand']['hsv_palm_max'][1], config['hand']['hsv_palm_max'][2]])

kernel = np.ones((5, 5), np.float32) / 25
blurred = cv2.filter2D(self.currentFrame.copy(), -1, kernel)
Expand Down Expand Up @@ -134,9 +134,9 @@ def FindHandFromTrack(self):
hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV)

self.hand_lower_blue = self.AddValueToColorArray(
[-config['hand']['hsv_dec_blue'][0], -config['hand']['hsv_dec_blue'][1], -config['hand']['hsv_dec_blue'][2]], self.handPointHSV.copy())
[-config['hand']['hsv_hand_dec'][0], -config['hand']['hsv_hand_dec'][1], -config['hand']['hsv_hand_dec'][2]], self.handPointHSV.copy())
self.hand_upper_blue = self.AddValueToColorArray(
[config['hand']['hsv_inc_blue'][0], config['hand']['hsv_inc_blue'][1], config['hand']['hsv_inc_blue'][2]], self.handPointHSV.copy())
[config['hand']['hsv_hand_inc'][0], config['hand']['hsv_hand_inc'][1], config['hand']['hsv_hand_inc'][2]], self.handPointHSV.copy())

mask = cv2.inRange(hsv, self.hand_lower_blue, self.hand_upper_blue)
self.mask_rafined = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
Expand Down
66 changes: 33 additions & 33 deletions Motion/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ def ManageMotion():
motion = Motion()

# Param on the fly
cv2.namedWindow('paramMinMax')
cv2.createTrackbar('MAX H', 'paramMinMax', 1, 255, nothing)
cv2.createTrackbar('MAX S', 'paramMinMax', 1, 255, nothing)
cv2.createTrackbar('MAX V', 'paramMinMax', 1, 255, nothing)
cv2.createTrackbar('MIN H', 'paramMinMax', 1, 255, nothing)
cv2.createTrackbar('MIN S', 'paramMinMax', 1, 255, nothing)
cv2.createTrackbar('MIN V', 'paramMinMax', 1, 255, nothing)

cv2.setTrackbarPos('MAX H', 'paramMinMax', config['hand']['hsv_max_blue'][0])
cv2.setTrackbarPos('MAX S', 'paramMinMax', config['hand']['hsv_max_blue'][1])
cv2.setTrackbarPos('MAX V', 'paramMinMax', config['hand']['hsv_max_blue'][2])
cv2.setTrackbarPos('MIN H', 'paramMinMax', config['hand']['hsv_min_blue'][0])
cv2.setTrackbarPos('MIN S', 'paramMinMax', config['hand']['hsv_min_blue'][1])
cv2.setTrackbarPos('MIN V', 'paramMinMax', config['hand']['hsv_min_blue'][2])

cv2.namedWindow('paramSearchRange')
cv2.createTrackbar('INC H', 'paramSearchRange', 1, 255, nothing)
cv2.createTrackbar('INC S', 'paramSearchRange', 1, 255, nothing)
cv2.createTrackbar('INC V', 'paramSearchRange', 1, 255, nothing)
cv2.createTrackbar('DEC H', 'paramSearchRange', 1, 255, nothing)
cv2.createTrackbar('DEC S', 'paramSearchRange', 1, 255, nothing)
cv2.createTrackbar('DEC V', 'paramSearchRange', 1, 255, nothing)

cv2.setTrackbarPos('INC H', 'paramSearchRange', config['hand']['hsv_inc_blue'][0])
cv2.setTrackbarPos('INC S', 'paramSearchRange', config['hand']['hsv_inc_blue'][1])
cv2.setTrackbarPos('INC V', 'paramSearchRange', config['hand']['hsv_inc_blue'][2])
cv2.setTrackbarPos('DEC H', 'paramSearchRange', config['hand']['hsv_dec_blue'][0])
cv2.setTrackbarPos('DEC S', 'paramSearchRange', config['hand']['hsv_dec_blue'][1])
cv2.setTrackbarPos('DEC V', 'paramSearchRange', config['hand']['hsv_dec_blue'][2])
cv2.namedWindow('paramMinMaxPalm')
cv2.createTrackbar('MAX H', 'paramMinMaxPalm', 1, 255, nothing)
cv2.createTrackbar('MAX S', 'paramMinMaxPalm', 1, 255, nothing)
cv2.createTrackbar('MAX V', 'paramMinMaxPalm', 1, 255, nothing)
cv2.createTrackbar('MIN H', 'paramMinMaxPalm', 1, 255, nothing)
cv2.createTrackbar('MIN S', 'paramMinMaxPalm', 1, 255, nothing)
cv2.createTrackbar('MIN V', 'paramMinMaxPalm', 1, 255, nothing)

cv2.setTrackbarPos('MAX H', 'paramMinMaxPalm', config['hand']['hsv_palm_max'][0])
cv2.setTrackbarPos('MAX S', 'paramMinMaxPalm', config['hand']['hsv_palm_max'][1])
cv2.setTrackbarPos('MAX V', 'paramMinMaxPalm', config['hand']['hsv_palm_max'][2])
cv2.setTrackbarPos('MIN H', 'paramMinMaxPalm', config['hand']['hsv_palm_min'][0])
cv2.setTrackbarPos('MIN S', 'paramMinMaxPalm', config['hand']['hsv_palm_min'][1])
cv2.setTrackbarPos('MIN V', 'paramMinMaxPalm', config['hand']['hsv_palm_min'][2])

cv2.namedWindow('paramSearchRangeHand')
cv2.createTrackbar('INC H', 'paramSearchRangeHand', 1, 255, nothing)
cv2.createTrackbar('INC S', 'paramSearchRangeHand', 1, 255, nothing)
cv2.createTrackbar('INC V', 'paramSearchRangeHand', 1, 255, nothing)
cv2.createTrackbar('DEC H', 'paramSearchRangeHand', 1, 255, nothing)
cv2.createTrackbar('DEC S', 'paramSearchRangeHand', 1, 255, nothing)
cv2.createTrackbar('DEC V', 'paramSearchRangeHand', 1, 255, nothing)

cv2.setTrackbarPos('INC H', 'paramSearchRangeHand', config['hand']['hsv_hand_inc'][0])
cv2.setTrackbarPos('INC S', 'paramSearchRangeHand', config['hand']['hsv_hand_inc'][1])
cv2.setTrackbarPos('INC V', 'paramSearchRangeHand', config['hand']['hsv_hand_inc'][2])
cv2.setTrackbarPos('DEC H', 'paramSearchRangeHand', config['hand']['hsv_hand_dec'][0])
cv2.setTrackbarPos('DEC S', 'paramSearchRangeHand', config['hand']['hsv_hand_dec'][1])
cv2.setTrackbarPos('DEC V', 'paramSearchRangeHand', config['hand']['hsv_hand_dec'][2])
frameIdx = 0
currentSliding = "None"
timeElapsedSinceLastSlide = time.time()
Expand All @@ -61,10 +61,10 @@ def ManageMotion():
main.ManageCommands(motion)

# Refresh config from param
config['hand']['hsv_upper_blue'] = [cv2.getTrackbarPos('MAX H', 'paramMinMax'), cv2.getTrackbarPos('MAX S', 'paramMinMax'), cv2.getTrackbarPos('MAX V', 'paramMinMax')]
config['hand']['hsv_lower_blue'] = [cv2.getTrackbarPos('MIN H', 'paramMinMax'), cv2.getTrackbarPos('MIN S', 'paramMinMax'), cv2.getTrackbarPos('MIN V', 'paramMinMax')]
config['hand']['hsv_inc_blue'] = [cv2.getTrackbarPos('INC H', 'paramSearchRange'), cv2.getTrackbarPos('INC S', 'paramSearchRange'), cv2.getTrackbarPos('INC V', 'paramSearchRange')]
config['hand']['hsv_dec_blue'] = [cv2.getTrackbarPos('DEC H', 'paramSearchRange'), cv2.getTrackbarPos('DEC S', 'paramSearchRange'), cv2.getTrackbarPos('DEC V', 'paramSearchRange')]
config['hand']['hsv_palm_max'] = [cv2.getTrackbarPos('MAX H', 'paramMinMaxPalm'), cv2.getTrackbarPos('MAX S', 'paramMinMaxPalm'), cv2.getTrackbarPos('MAX V', 'paramMinMaxPalm')]
config['hand']['hsv_palm_min'] = [cv2.getTrackbarPos('MIN H', 'paramMinMaxPalm'), cv2.getTrackbarPos('MIN S', 'paramMinMaxPalm'), cv2.getTrackbarPos('MIN V', 'paramMinMaxPalm')]
config['hand']['hsv_hand_inc'] = [cv2.getTrackbarPos('INC H', 'paramSearchRangeHand'), cv2.getTrackbarPos('INC S', 'paramSearchRangeHand'), cv2.getTrackbarPos('INC V', 'paramSearchRangeHand')]
config['hand']['hsv_hand_dec'] = [cv2.getTrackbarPos('DEC H', 'paramSearchRangeHand'), cv2.getTrackbarPos('DEC S', 'paramSearchRangeHand'), cv2.getTrackbarPos('DEC V', 'paramSearchRangeHand')]

# Manage motion and gestures
motion.GetInformationOnNextFrame()
Expand Down

0 comments on commit 27f92b9

Please sign in to comment.