def gesture():
pygame.init()
pygame.mixer.init()
cap = cv2.VideoCapture(1)
detector = HandDetector(detectionCon=0.8, maxHands=1)
file1 = "/Users/changmichelle/Desktop/music/깨어나.mp3"
file2 = "/Users/changmichelle/Desktop/music/All Falls Down.mp3"
file3 = "/Users/changmichelle/Desktop/music/Unity.mp3"
file4 = "/Users/changmichelle/Desktop/music/I Wanna Know.mp3"
start_mode1 = False
start_mode2 = False
start_mode3 = False
start_mode4 = False
while True:
print("ouo")
success, img = cap.read()
img = cv2.flip(img, 1)
hands, img = detector.findHands(img)
if hands:
hand1 = hands[0]
lmList1 = hand1["lmList"]
bbox1 = hand1["bbox"]
centerPoint1 = hand1["center"]
handType1 = hand1["type"]
fingers1 = detector.fingersUp(hand1)
totalFingers = fingers1.count(1)
cv2.putText(
img,
f"Fingers:{totalFingers}",
(bbox1[0] + 200, bbox1[1] - 30),
cv2.FONT_HERSHEY_PLAIN,
2,
(0, 255, 0),
2,
)
if len(hands) == 2:
hand2 = hands[1]
lmList2 = hand2["lmList"]
bbox2 = hand2["bbox"]
centerPoint2 = hand2["center"]
handType2 = hand2["type"]
fingers2 = detector.fingersUp(hand2)
length, info, img = detector.findDistance(lmList1[8], lmList2[8], img)
if totalFingers == 1:
if start_mode1 == False:
pygame.mixer.music.load(file1)
pygame.mixer.music.play()
start_mode1 = True
start_mode2 = False
start_mode3 = False
start_mode4 = False
elif totalFingers == 2:
if start_mode2 == False:
pygame.mixer.music.load(file2)
pygame.mixer.music.play()
start_mode2 = True
start_mode1 = False
start_mode3 = False
start_mode4 = False
elif totalFingers == 3:
if start_mode3 == False:
pygame.mixer.music.load(file3)
pygame.mixer.music.play()
start_mode3 = True
start_mode1 = False
start_mode2 = False
start_mode4 = False
elif totalFingers == 4:
if start_mode4 == False:
pygame.mixer.music.load(file4)
pygame.mixer.music.play()
start_mode4 = True
start_mode1 = False
start_mode2 = False
start_mode3 = False
#......