-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlay.py
More file actions
84 lines (65 loc) · 2.84 KB
/
overlay.py
File metadata and controls
84 lines (65 loc) · 2.84 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Links directly in scanner.py
from voice import speak_text
def showMoves(cv2, WINDOW_NAME, FRAME_WIDTH, FRAME_HEIGHT, cap, moves):
user_stopped = False
total_moves = len(moves)
current_step = 0
COLORS = {
"title": (0, 0, 0),
"sub": (255, 200, 0),
"warn": (0, 0, 255),
"progress": (0, 200, 0),
"progress_bg": (50, 50, 50), # Dark background
}
for move in moves:
speak_text(move)
msg_frames = 90 # 3 seconds at ~30 FPS
while msg_frames > 0:
ret, frame = cap.read()
if not ret:
user_stopped = True
break
frame = cv2.flip(frame, 1)
# Top instructions
cv2.putText(frame, "Position Cube Correctly", (20, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.8, COLORS["title"], 2)
cv2.putText(frame, "W: Up | R: Right | G: Front", (20, 65),
cv2.FONT_HERSHEY_SIMPLEX, 0.6, COLORS["sub"], 2)
cv2.putText(frame, "Y: Down | O: Left | B: Back", (20, 90),
cv2.FONT_HERSHEY_SIMPLEX, 0.6, COLORS["sub"], 2)
# Remaining moves
moves_left = total_moves - current_step - 1
cv2.putText(frame, f"Moves left: {moves_left}", (FRAME_WIDTH - 180, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, COLORS["warn"], 2)
# Moves overlay
cv2.putText(frame, f"Please Do: ( {move} )", (20, FRAME_HEIGHT - 40),
cv2.FONT_HERSHEY_TRIPLEX, 1, (0, 255, 255), 2)
# Progress Bar
progress_ratio = (current_step + 1) / total_moves
bar_length = int(FRAME_WIDTH * progress_ratio)
cv2.rectangle(frame, (0, FRAME_HEIGHT - 10), (FRAME_WIDTH, FRAME_HEIGHT), COLORS["progress_bg"], -1)
cv2.rectangle(frame, (0, FRAME_HEIGHT - 10), (bar_length, FRAME_HEIGHT), COLORS["progress"], -1)
cv2.imshow(WINDOW_NAME, frame)
key = cv2.waitKey(33) & 0xFF
if key == ord('q') or cv2.getWindowProperty(WINDOW_NAME, cv2.WND_PROP_VISIBLE) < 1:
user_stopped = True
break
msg_frames -= 1
current_step += 1
if user_stopped:
break
# Cube solved message
final_frames = 90 # 3 seconds
while final_frames > 0:
ret, frame = cap.read()
if not ret:
break
frame = cv2.flip(frame, 1)
cv2.putText(frame, "Cube Solved!", (FRAME_WIDTH // 4, FRAME_HEIGHT // 2),
cv2.FONT_HERSHEY_DUPLEX, 1.5, (0, 255, 0), 4)
cv2.imshow(WINDOW_NAME, frame)
if cv2.waitKey(33) & 0xFF == ord('q'):
break
final_frames -= 1
cv2.destroyAllWindows()
return "User stopped the process." if user_stopped else "🎉 Cube solved! All moves completed."