Skip to content

Commit 2e222ee

Browse files
version 0.0
1 parent 32de2b2 commit 2e222ee

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

main.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import cv2
2+
from cvzone.HandTrackingModule import HandDetector
3+
import os
4+
import time
5+
6+
# select camera and make a fream
7+
cap = cv2.VideoCapture(0)
8+
cap.set(3, 1280)
9+
cap.set(4, 720)
10+
11+
# make a detector for hand
12+
detector = HandDetector(detectionCon=0.7, maxHands= 2)
13+
14+
pTime = 0
15+
16+
# for select finger image path
17+
img_path = "NewFingerPic"
18+
img_list = os.listdir(img_path)
19+
20+
# for make a finger image list
21+
hand_img = []
22+
for i in img_list:
23+
image = cv2.imread(f"{img_path}/{i}")
24+
hand_img.append(image)
25+
26+
while True:
27+
success, img = cap.read()
28+
29+
# for flip video capture
30+
img = cv2.flip(img, 1)
31+
32+
# detect hand
33+
hands, img = detector.findHands(img)
34+
35+
# for make FPS
36+
cTime = time.time()
37+
fps = 1/(cTime - pTime)
38+
pTime = cTime
39+
40+
# for print FPS in video fream
41+
cv2.putText(img, f"FPS:{int(fps)}", (1100, 50), cv2.FONT_HERSHEY_PLAIN, 3, (255,0,0),3)
42+
43+
if len(hands) == 1:
44+
# detect fingers
45+
hand_fingers = detector.fingersUp(hands[0])
46+
if hand_fingers == [0,0,0,0,0] :
47+
img[0:400, 0:400] = hand_img[0]
48+
elif hand_fingers == [0,1,0,0,0]:
49+
img[0:400, 0:400] = hand_img[1]
50+
elif hand_fingers == [0,1,1,0,0]:
51+
img[0:400, 0:400] = hand_img[2]
52+
elif hand_fingers == [0,1,1,1,0]:
53+
img[0:400, 0:400] = hand_img[3]
54+
elif hand_fingers == [0,1,1,1,1]:
55+
img[0:400, 0:400] = hand_img[4]
56+
elif hand_fingers == [1,1,1,1,1]:
57+
img[0:400, 0:400] = hand_img[5]
58+
else:
59+
img[0:400, 0:400] = hand_img[8]
60+
61+
elif len(hands) == 2:
62+
img[0:400, 0:400] = hand_img[7]
63+
else:
64+
img[0:400, 0:400] = hand_img[6]
65+
66+
cv2.imshow("Problem Solve With Ridoy", img)
67+
if cv2.waitKey(1) & 0xFF == ord("q"):
68+
break

0 commit comments

Comments
 (0)