-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_test_data.py
More file actions
89 lines (68 loc) · 3.27 KB
/
create_test_data.py
File metadata and controls
89 lines (68 loc) · 3.27 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
"""Generate a synthetic test video and GPS JSON for testing the pipeline."""
import json
from datetime import datetime, timedelta
import cv2
import numpy as np
def create_test_video(output_path: str, fps: int = 30, duration_sec: int = 10):
"""Create a simple test video simulating a road with a pothole."""
width, height = 640, 480
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
writer = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
total_frames = fps * duration_sec
for i in range(total_frames):
# Grey road background
frame = np.full((height, width, 3), (100, 100, 100), dtype=np.uint8)
# Draw road lines (white dashes)
for y in range(0, height, 40):
offset = (i * 3) % 40 # animate movement
cv2.line(frame, (width // 2, y - offset), (width // 2, y - offset + 20), (255, 255, 255), 2)
# Draw road edges
cv2.line(frame, (100, 0), (100, height), (200, 200, 200), 3)
cv2.line(frame, (540, 0), (540, height), (200, 200, 200), 3)
# Between frames 90-210 (seconds 3-7): draw a dark pothole-like shape
if 90 <= i <= 210:
center_x = 300
center_y = 300
axes = (40, 25)
cv2.ellipse(frame, (center_x, center_y), axes, 0, 0, 360, (30, 30, 30), -1)
# Add rough edges to make it look more like a pothole
cv2.ellipse(frame, (center_x, center_y), (45, 30), 0, 0, 360, (50, 50, 50), 2)
# Add text label for clarity
cv2.putText(frame, "POTHOLE", (center_x - 40, center_y - 40),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)
# Between frames 240-300 (seconds 8-10): draw debris on road
if 240 <= i <= 300:
# Random-ish debris shapes
pts = np.array([[350, 200], [380, 190], [390, 210], [370, 220], [345, 215]], np.int32)
cv2.fillPoly(frame, [pts], (0, 80, 150))
cv2.putText(frame, "DEBRIS", (340, 180),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)
# Add frame number
cv2.putText(frame, f"Frame {i}", (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 1)
writer.write(frame)
writer.release()
print(f"Test video created: {output_path} ({total_frames} frames, {duration_sec}s)")
def create_test_gps_json(output_path: str, duration_sec: int = 10):
"""Create a GPS JSON file with ~3 entries per second."""
start_time = datetime(2026, 3, 21, 10, 0, 0)
start_lat = 40.7128
start_lon = -74.0060
entries = []
intervals_per_sec = 3 # multiple entries per second
for i in range(duration_sec * intervals_per_sec):
t = start_time + timedelta(milliseconds=i * (1000 // intervals_per_sec))
# Simulate slow movement north
lat = start_lat + (i * 0.00001)
lon = start_lon + (i * 0.000005)
entries.append({
"timestamp": t.isoformat(),
"gps_lat": round(lat, 7),
"gps_lon": round(lon, 7),
})
with open(output_path, "w") as f:
json.dump(entries, f, indent=2)
print(f"GPS JSON created: {output_path} ({len(entries)} entries)")
if __name__ == "__main__":
create_test_video("test_video.mp4")
create_test_gps_json("test_gps.json")