-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (48 loc) · 1.71 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
from spotifyvision import SpotifyVision
from ultralytics import YOLO
import cv2
import math
from time import sleep
sv = SpotifyVision()
cap = cv2.VideoCapture(0)
print("Camera is ready!\n")
model = YOLO("best.pt")
classNames = ["like", "pause_resume", "redo", "stop", "skip"]
stop = False
sv.select_playlist()
print(sv.print_playing())
while True:
success, img = cap.read()
results = model(img, stream=True, verbose=False)
for r in results:
for box in r.boxes:
action = classNames[int(box.cls[0])]
confidence = math.ceil((box.conf[0]*100))/100
# Uncomment the line below to see the confidence of the model
# print(f"Action: {action}, Confidence: {confidence}")
status = sv.is_playing()
if action == "pause_resume" and status == False and confidence > 0.65:
print(sv.print_playing())
sv.resume()
sleep(2)
elif action == "pause_resume" and status == True and confidence > 0.65:
print(sv.print_paused())
sv.pause()
sleep(2)
elif action == "skip" and confidence > 0.65:
sv.next_song()
print(sv.print_playing())
sleep(2)
elif action == "like" and confidence > 0.65:
sv.like_song()
print(sv.print_liked())
sleep(2)
elif action == "stop" and confidence > 0.65:
if status == True:
sv.pause()
print("Stopped")
stop = True
if stop == True:
break
cap.release()
cv2.destroyAllWindows()