-
Notifications
You must be signed in to change notification settings - Fork 0
/
finger_counter.py
45 lines (39 loc) · 1.46 KB
/
finger_counter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import cv2
from hand_tracking.hand_tracking import HandDetector
if __name__ == '__main__':
cap = cv2.VideoCapture(0)
detect = HandDetector()
while True:
_, image = cap.read()
cv2.rectangle(img=image,
pt1=(0, 0),
pt2=(100, 100),
color=(0, 255, 0),
thickness=cv2.FILLED
)
if _:
detect.find_hands(image)
result = detect.find_position(image=image)
count = 0
if len(result) > 0:
if result[8][1] > result[6][1]: # checking finger
count += 1
if result[4][1] > result[3][1]: # checking thumb
count += 1
if result[12][1] > result[10][1]: # checking middle finger
count += 1
if result[16][1] > result[14][1]: # checking 4th finger
count += 1
if result[20][1] > result[18][1]:
count += 1
print(count)
cv2.putText(img=image,
text=str(count),
org=(50, 50),
fontFace=cv2.FONT_HERSHEY_SIMPLEX,
fontScale=1,
color=(0, 0, 0),
thickness=2
)
cv2.imshow('live', image)
cv2.waitKey(1)