-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy path05_text_scroller_callback.py
More file actions
128 lines (96 loc) · 4.03 KB
/
05_text_scroller_callback.py
File metadata and controls
128 lines (96 loc) · 4.03 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"""Stream animated graphics (text scroller, gradient, shapes) using frame callbacks."""
from avp_stream.streamer import VisionProStreamer
import cv2
import numpy as np
import time
def text_scroller_callback():
"""Create a scrolling text animation callback"""
start_time = time.time()
message = "Hello VisionPro! This is a synthetic video stream without a camera!"
def generate_frame(blank_frame):
elapsed = time.time() - start_time
h, w = blank_frame.shape[:2]
# Gradient background
for y in range(h):
color = int(255 * y / h)
blank_frame[y, :] = [color, color // 2, 255 - color]
# Scrolling text
text_x = int(w - (elapsed * 100) % (w + 1000))
cv2.putText(blank_frame, message, (text_x, h // 2),
cv2.FONT_HERSHEY_SIMPLEX, 1.5, (255, 255, 255), 3)
return blank_frame
return generate_frame
def animated_gradient_callback():
"""Create an animated gradient effect callback"""
start_time = time.time()
def generate_frame(blank_frame):
elapsed = time.time() - start_time
h, w = blank_frame.shape[:2]
# Create animated gradient
for y in range(h):
for x in range(w):
r = int(127 + 127 * np.sin(elapsed + x * 0.01))
g = int(127 + 127 * np.sin(elapsed + y * 0.01))
b = int(127 + 127 * np.sin(elapsed + (x + y) * 0.01))
blank_frame[y, x] = [b, g, r]
# Add timestamp
cv2.putText(blank_frame, f"Time: {elapsed:.2f}s", (20, 40),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
return blank_frame
return generate_frame
def moving_shapes_callback():
"""Create moving geometric shapes callback"""
start_time = time.time()
def generate_frame(blank_frame):
elapsed = time.time() - start_time
h, w = blank_frame.shape[:2]
# Black background
blank_frame[:] = [0, 0, 0]
# Moving circle
circle_x = int(w/2 + w/3 * np.sin(elapsed))
circle_y = int(h/2 + h/3 * np.cos(elapsed))
cv2.circle(blank_frame, (circle_x, circle_y), 50, (0, 255, 0), -1)
# Moving rectangle
rect_x = int(w/2 + w/3 * np.cos(elapsed * 1.5))
rect_y = int(h/2 + h/3 * np.sin(elapsed * 1.5))
cv2.rectangle(blank_frame,
(rect_x - 30, rect_y - 30),
(rect_x + 30, rect_y + 30),
(255, 0, 0), -1)
# Add FPS counter
cv2.putText(blank_frame, f"Generated @ 60fps", (20, 40),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
return blank_frame
return generate_frame
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Callback Text Scroller for VisionPro")
parser.add_argument("--ip", type=str, required=True)
parser.add_argument("--mode", type=str, default="scroller",
choices=["scroller", "gradient", "shapes"],
help="Animation mode: scroller, gradient, or shapes")
args = parser.parse_args()
# Create streamer
streamer = VisionProStreamer(ip=args.ip)
# Choose callback based on mode
if args.mode == "scroller":
callback = text_scroller_callback()
elif args.mode == "gradient":
callback = animated_gradient_callback()
else:
callback = moving_shapes_callback()
# Register the callback
streamer.register_frame_callback(callback)
# Configure video streaming without device (synthetic mode)
streamer.configure_video(
fps=60,
size="1280x720",
)
streamer.start_webrtc(port=9999)
print(f"Streaming {args.mode} animation at 60fps using callbacks...")
print("Press Ctrl+C to stop")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nStopping...")