From 022653907ac3123613a977b785846a8f9db2bf92 Mon Sep 17 00:00:00 2001 From: culms Date: Tue, 6 Feb 2018 21:50:13 +0530 Subject: [PATCH 1/6] Some statement changed changes acc to version --- new.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/new.py b/new.py index e0df7c3..7010918 100644 --- a/new.py +++ b/new.py @@ -2,7 +2,7 @@ import numpy as np import copy import math -from appscript import app +#from appscript import app # Environment: # OS : Mac OS EL Capitan @@ -92,7 +92,7 @@ def calculateFingers(res,drawing): # -> finished bool, cnt: finger count # get the coutours thresh1 = copy.deepcopy(thresh) - contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) + im2,contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) length = len(contours) maxArea = -1 if length> 0: @@ -112,8 +112,9 @@ def calculateFingers(res,drawing): # -> finished bool, cnt: finger count isFinishCal,cnt = calculateFingers(res,drawing) if triggerSwitch is True: if isFinishCal is True and cnt <= 2: - print cnt - app('System Events').keystroke(' ') # simulate pressing blank space + print (cnt) + #app('System Events').keystroke(' ') # simulate pressing blank space + cv2.imshow('output', drawing) @@ -122,14 +123,14 @@ def calculateFingers(res,drawing): # -> finished bool, cnt: finger count if k == 27: # press ESC to exit break elif k == ord('b'): # press 'b' to capture the background - bgModel = cv2.BackgroundSubtractorMOG2(0, bgSubThreshold) + bgModel = cv2.createBackgroundSubtractorMOG2(0, bgSubThreshold) isBgCaptured = 1 - print '!!!Background Captured!!!' + print( '!!!Background Captured!!!') elif k == ord('r'): # press 'r' to reset the background bgModel = None triggerSwitch = False isBgCaptured = 0 - print '!!!Reset BackGround!!!' + print ('!!!Reset BackGround!!!') elif k == ord('n'): triggerSwitch = True - print '!!!Trigger On!!!' \ No newline at end of file + print ('!!!Trigger On!!!') \ No newline at end of file From bc53c053f23906742c9ecd7eb6758c494687e542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lzane=20=E6=9D=8E=E6=BE=A4=E5=B8=86?= Date: 2018年5月21日 13:49:21 +0800 Subject: [PATCH 2/6] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cbe3fef..50392d3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -> for people using python3 and opencv3, please check out the `lzane:py3_opencv3` branch. +> for people using python2 and opencv2, please check out the [`lzane:py2_opencv2`](https://github.com/lzane/Fingers-Detection-using-OpenCV-and-Python/tree/py2_opencv2) branch. ## Environment - OS: MacOS El Capitan -- Platform: Python 2.7.12 +- Platform: Python 3 - Librarys: - - OpenCV 2.4.13 + - OpenCV 3 - appscript From 0b57a6dabb2da5ba1c9e9b3e2ce5aa89919e662b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lzane=20=E6=9D=8E=E6=BE=A4=E5=B8=86?= Date: Sat, 2 Jun 2018 22:54:43 +0800 Subject: [PATCH 3/6] [!] add learningRate https://docs.opencv.org/3.4/d7/d7b/classcv_1_1BackgroundSubtractorMOG2.html#a682adde901148d85450435e6cc0de4a1 --- new.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/new.py b/new.py index 7010918..70182df 100644 --- a/new.py +++ b/new.py @@ -15,6 +15,7 @@ threshold = 60 # BINARY threshold blurValue = 41 # GaussianBlur parameter bgSubThreshold = 50 +learningRate = 0 # variables isBgCaptured = 0 # bool, whether the background captured @@ -25,7 +26,7 @@ def printThreshold(thr): def removeBG(frame): - fgmask = bgModel.apply(frame) + fgmask = bgModel.apply(frame,learningRate=learningRate) # kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) # res = cv2.morphologyEx(fgmask, cv2.MORPH_OPEN, kernel) @@ -92,7 +93,7 @@ def calculateFingers(res,drawing): # -> finished bool, cnt: finger count # get the coutours thresh1 = copy.deepcopy(thresh) - im2,contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) + _,contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) length = len(contours) maxArea = -1 if length> 0: From 991a551dc17ed2cab98bb9a09a71ddf4cafa08e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LZANE=20=7C=20=E6=9D=8E=E6=B3=BD=E5=B8=86?= Date: 2019年2月12日 11:27:21 +0800 Subject: [PATCH 4/6] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e6f2ada --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 LZANE | 李泽帆 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From c467c33a193c8328bbdab71b1d914c4ae00284fa Mon Sep 17 00:00:00 2001 From: Vinay Kumar Verma <31174918+vermavinay982@users.noreply.github.com> Date: 2019年4月23日 11:45:19 +0530 Subject: [PATCH 5/6] Fixed the closing of windows and releasing of camera. after the execution of program the camera is struck and cant be used again. python goes into error and stops responding and the windows remain struck there as they were. this error is repaired now --- new.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/new.py b/new.py index 70182df..efbb028 100644 --- a/new.py +++ b/new.py @@ -122,6 +122,8 @@ def calculateFingers(res,drawing): # -> finished bool, cnt: finger count # Keyboard OP k = cv2.waitKey(10) if k == 27: # press ESC to exit + camera.release() + cv2.destroyAllWindows() break elif k == ord('b'): # press 'b' to capture the background bgModel = cv2.createBackgroundSubtractorMOG2(0, bgSubThreshold) @@ -134,4 +136,4 @@ def calculateFingers(res,drawing): # -> finished bool, cnt: finger count print ('!!!Reset BackGround!!!') elif k == ord('n'): triggerSwitch = True - print ('!!!Trigger On!!!') \ No newline at end of file + print ('!!!Trigger On!!!') From 6aa52befa1275725327fe4a4b5fe677ac717ebb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LZANE=20=7C=20=E6=9D=8E=E6=B3=BD=E5=B8=86?= Date: 2019年8月24日 22:42:42 +0800 Subject: [PATCH 6/6] Update README.md opencv4 api changed --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 50392d3..699242f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ > for people using python2 and opencv2, please check out the [`lzane:py2_opencv2`](https://github.com/lzane/Fingers-Detection-using-OpenCV-and-Python/tree/py2_opencv2) branch. +> for people using opencv4, please change line 96 in the `new.py` to `contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)` according to the [opencv api change](https://github.com/lzane/Fingers-Detection-using-OpenCV-and-Python/issues/7#issuecomment-509925971). + + ## Environment - OS: MacOS El Capitan - Platform: Python 3

AltStyle によって変換されたページ (->オリジナル) /