-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (55 loc) · 1.74 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import cv2
from cvzone.HandTrackingModule import HandDetector
import os
import time
# select camera and make a fream
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
# make a detector for hand
detector = HandDetector(detectionCon=0.7, maxHands= 2)
pTime = 0
# for select finger image path
img_path = "NewFingerPic"
img_list = os.listdir(img_path)
# for make a finger image list
hand_img = []
for i in img_list:
image = cv2.imread(f"{img_path}/{i}")
hand_img.append(image)
while True:
success, img = cap.read()
# for flip video capture
img = cv2.flip(img, 1)
# detect hand
hands, img = detector.findHands(img)
# for make FPS
cTime = time.time()
fps = 1/(cTime - pTime)
pTime = cTime
# for print FPS in video fream
cv2.putText(img, f"FPS:{int(fps)}", (1100, 50), cv2.FONT_HERSHEY_PLAIN, 3, (255,0,0),3)
if len(hands) == 1:
# detect fingers
hand_fingers = detector.fingersUp(hands[0])
if hand_fingers == [0,0,0,0,0] :
img[0:400, 0:400] = hand_img[0]
elif hand_fingers == [0,1,0,0,0]:
img[0:400, 0:400] = hand_img[1]
elif hand_fingers == [0,1,1,0,0]:
img[0:400, 0:400] = hand_img[2]
elif hand_fingers == [0,1,1,1,0]:
img[0:400, 0:400] = hand_img[3]
elif hand_fingers == [0,1,1,1,1]:
img[0:400, 0:400] = hand_img[4]
elif hand_fingers == [1,1,1,1,1]:
img[0:400, 0:400] = hand_img[5]
else:
img[0:400, 0:400] = hand_img[8]
elif len(hands) == 2:
img[0:400, 0:400] = hand_img[7]
else:
img[0:400, 0:400] = hand_img[6]
cv2.imshow("Problem Solve With Ridoy", img)
if cv2.waitKey(1) & 0xFF == ord("q"):
break