22import numpy as np
33import copy
44import math
5- from appscript import app
5+ # from appscript import app
66
77# Environment:
88# OS : Mac OS EL Capitan
@@ -92,7 +92,7 @@ def calculateFingers(res,drawing): # -> finished bool, cnt: finger count
9292
9393 # get the coutours
9494 thresh1 = copy .deepcopy (thresh )
95- contours , hierarchy = cv2 .findContours (thresh1 , cv2 .RETR_TREE , cv2 .CHAIN_APPROX_SIMPLE )
95+ im2 , contours , hierarchy = cv2 .findContours (thresh1 , cv2 .RETR_TREE , cv2 .CHAIN_APPROX_SIMPLE )
9696 length = len (contours )
9797 maxArea = - 1
9898 if length > 0 :
@@ -112,8 +112,9 @@ def calculateFingers(res,drawing): # -> finished bool, cnt: finger count
112112 isFinishCal ,cnt = calculateFingers (res ,drawing )
113113 if triggerSwitch is True :
114114 if isFinishCal is True and cnt <= 2 :
115- print cnt
116- app ('System Events' ).keystroke (' ' ) # simulate pressing blank space
115+ print (cnt )
116+ #app('System Events').keystroke(' ') # simulate pressing blank space
117+ 117118
118119 cv2 .imshow ('output' , drawing )
119120
@@ -122,14 +123,14 @@ def calculateFingers(res,drawing): # -> finished bool, cnt: finger count
122123 if k == 27 : # press ESC to exit
123124 break
124125 elif k == ord ('b' ): # press 'b' to capture the background
125- bgModel = cv2 .BackgroundSubtractorMOG2 (0 , bgSubThreshold )
126+ bgModel = cv2 .createBackgroundSubtractorMOG2 (0 , bgSubThreshold )
126127 isBgCaptured = 1
127- print '!!!Background Captured!!!'
128+ print ( '!!!Background Captured!!!' )
128129 elif k == ord ('r' ): # press 'r' to reset the background
129130 bgModel = None
130131 triggerSwitch = False
131132 isBgCaptured = 0
132- print '!!!Reset BackGround!!!'
133+ print ( '!!!Reset BackGround!!!' )
133134 elif k == ord ('n' ):
134135 triggerSwitch = True
135- print '!!!Trigger On!!!'
136+ print ( '!!!Trigger On!!!' )
0 commit comments