Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions HandRecognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Variables & parameters
hsv_thresh_lower=150
gaussian_ksize=11
gaussian_ksize=15
gaussian_sigma=0
morph_elem_size=13
median_ksize=3
Expand All @@ -37,7 +37,7 @@
def hand_capture(frame_in,box_x,box_y):
hsv = cv2.cvtColor(frame_in, cv2.COLOR_BGR2HSV)
ROI = np.zeros([capture_box_dim*capture_box_count,capture_box_dim,3], dtype=hsv.dtype)
for i in xrange(capture_box_count):
for i in range(capture_box_count):
ROI[i*capture_box_dim:i*capture_box_dim+capture_box_dim,0:capture_box_dim] = hsv[box_y[i]:box_y[i]+capture_box_dim,box_x[i]:box_x[i]+capture_box_dim]
hand_hist = cv2.calcHist([ROI],[0, 1], None, [180, 256], [0, 180, 0, 256])
cv2.normalize(hand_hist,hand_hist, 0, 255, cv2.NORM_MINMAX)
Expand Down Expand Up @@ -137,8 +137,8 @@ def mark_hand_center(frame_in,cont):
max_d=0
pt=(0,0)
x,y,w,h = cv2.boundingRect(cont)
for ind_y in xrange(int(y+0.3*h),int(y+0.8*h)): #around 0.25 to 0.6 region of height (Faster calculation with ok results)
for ind_x in xrange(int(x+0.3*w),int(x+0.6*w)): #around 0.3 to 0.6 region of width (Faster calculation with ok results)
for ind_y in range(int(y+0.3*h),int(y+0.8*h)): #around 0.25 to 0.6 region of height (Faster calculation with ok results)
for ind_x in range(int(x+0.3*w),int(x+0.6*w)): #around 0.3 to 0.6 region of width (Faster calculation with ok results)
dist= cv2.pointPolygonTest(cont,(ind_x,ind_y),True)
if(dist>max_d):
max_d=dist
Expand Down Expand Up @@ -204,7 +204,7 @@ def remove_bg(frame):
else:
frame=hand_threshold(fg_frame,hand_histogram)
contour_frame=np.copy(frame)
contours,hierarchy=cv2.findContours(contour_frame,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
_,contours,hierarchy=cv2.findContours(contour_frame,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
found,hand_contour=hand_contour_find(contours)
if(found):
hand_convex_hull=cv2.convexHull(hand_contour)
Expand All @@ -229,7 +229,7 @@ def remove_bg(frame):
hand_histogram=hand_capture(frame_original,box_pos_x,box_pos_y)
# Capture background by pressing 'b'
elif interrupt & 0xFF == ord('b'):
bg_model = cv2.BackgroundSubtractorMOG2(0,10)
bg_model = cv2.createBackgroundSubtractorMOG2(0,10)
bg_captured=1
# Reset captured hand by pressing 'r'
elif interrupt & 0xFF == ord('r'):
Expand Down