-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlay.py
More file actions
83 lines (64 loc) · 2.78 KB
/
Copy pathoverlay.py
File metadata and controls
83 lines (64 loc) · 2.78 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
"""On-screen UI helpers (palette, status bar, hand skeleton, cursor)."""
import cv2
from config import COLORS, HAND_CONNECTIONS, FONT
def draw_palette(frame, active_idx):
h, w = frame.shape[:2]
# dark strip at top
overlay = frame.copy()
cv2.rectangle(overlay, (0, 0), (w, 80), (25, 25, 25), -1)
cv2.addWeighted(overlay, 0.7, frame, 0.3, 0, frame)
radius, gap = 22, 14
step = 2 * radius + gap
total_width = len(COLORS) * step - gap
origin_x = (w - total_width) // 2
for i, (bgr, name) in enumerate(COLORS):
cx = origin_x + i * step + radius
cy = 40
cv2.circle(frame, (cx, cy), radius, bgr, -1)
cv2.putText(frame, str(i + 1), (cx - 5, cy + 5),
FONT, 0.4, (0, 0, 0), 2, cv2.LINE_AA)
if i == active_idx:
cv2.circle(frame, (cx, cy), radius + 5, (255, 255, 255), 2)
cv2.putText(frame, name, (cx - 18, cy + radius + 16),
FONT, 0.4, (255, 255, 255), 1, cv2.LINE_AA)
def draw_status(frame, gesture, brush_size, fps):
"""Bottom status bar with current gesture and keyboard hints."""
h, w = frame.shape[:2]
overlay = frame.copy()
cv2.rectangle(overlay, (0, h - 40), (w, h), (25, 25, 25), -1)
cv2.addWeighted(overlay, 0.7, frame, 0.3, 0, frame)
labels = {
"point": "DRAW", "fist": "PAUSE",
"pinch": "SWITCH COLOR", "other": "-",
}
tints = {
"point": (0, 230, 80), "fist": (60, 120, 255),
"pinch": (80, 200, 255), "other": (150, 150, 150),
}
g = gesture or "other"
cv2.putText(frame, labels[g], (15, h - 12),
FONT, 0.6, tints[g], 2, cv2.LINE_AA)
info = (f"Brush:{brush_size}px | 1-8=Color C=Clear "
f"S=Save +/-=Size Q=Quit | FPS:{fps}")
cv2.putText(frame, info, (220, h - 12),
FONT, 0.38, (170, 170, 170), 1, cv2.LINE_AA)
def draw_hand(frame, landmarks, w, h):
# minimal skeleton overlay
pts = [(int(lm.x * w), int(lm.y * h)) for lm in landmarks]
for a, b in HAND_CONNECTIONS:
cv2.line(frame, pts[a], pts[b], (100, 100, 100), 1, cv2.LINE_AA)
for p in pts:
cv2.circle(frame, p, 3, (200, 200, 200), -1, cv2.LINE_AA)
def draw_cursor(frame, pos, gesture, color_bgr, brush_size):
"""Visual feedback at the fingertip."""
if pos is None:
return
if gesture == "point":
cv2.circle(frame, pos, brush_size // 2 + 4, color_bgr, -1, cv2.LINE_AA)
cv2.circle(frame, pos, brush_size // 2 + 6, (255, 255, 255), 2, cv2.LINE_AA)
elif gesture == "pinch":
cv2.circle(frame, pos, 20, color_bgr, 3, cv2.LINE_AA)
cv2.putText(frame, "+", (pos[0] - 8, pos[1] + 7),
FONT, 0.8, color_bgr, 2, cv2.LINE_AA)
else:
cv2.circle(frame, pos, 8, (180, 180, 180), 2, cv2.LINE_AA)