-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
46 lines (44 loc) · 1.54 KB
/
project.py
File metadata and controls
46 lines (44 loc) · 1.54 KB
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
from ast import Num
from tkinter.tix import Tree
import HandTrackingModule as ht
import cv2
import SoundPlayerModule as play
from playsound import playsound
Hand1 = [True, True, True, True]
Hand2 = [True, True, True, True]
Hands = [Hand1, Hand2]
tipIds = [8, 12 , 16 , 20]
def Moving(Hand = [], HandNo = 0, orientation = False):
for id in range(0,4):
if Hands[HandNo][id]:
if Hand[tipIds[id]][2] > Hand[int(tipIds[id]) - 2][2]:
playsound(play.SoundPlayer(HandNo, id), False)
Hands[HandNo][id] = False
print("Moving")
else:
if Hand[tipIds[id]][2] < Hand[int(tipIds[id]) - 2][2]:
Hands[HandNo][id] = True
wCam, hCam = 640, 480
cap = cv2.VideoCapture(0)
cap.set(3, wCam)
cap.set(4, hCam)
detector = ht.handDetectore()
FirstHand = []
SecondHand = []
while True:
ret, img = cap.read()
img = detector.findHands(img, draw=True)
if detector.results.multi_hand_landmarks:
if len(detector.results.multi_hand_landmarks) == 1:
FirstHand = detector.findPosition(img=img, handNo=0)
Moving(FirstHand, 0 , False)
if len(detector.results.multi_hand_landmarks) == 2:
FirstHand = detector.findPosition(img=img, handNo= 0)
SecondHand = detector.findPosition(img=img,handNo=1)
Moving(FirstHand, 0, False)
Moving(SecondHand, 1 , False)
cv2.imshow('Image', img)
if cv2.waitKey(1) == ord('q'):
break;
cap.release()
cv2.destroyAllWindows()