greenbot-dataset / tools /verify_v2.py
jlblancoc's picture
Calibration v2, figures, tools and dataset card
2a86f7e verified
Raw History Blame Contribute Delete
1.8 kB
"""Check a converted v2 bag against its v1 source: per-topic message counts and readability.
Usage: verify_v2.py <v1.bag> <v2_dir>
"""
import subprocess
import sys
from pathlib import Path
import yaml
from rosbags.rosbag1 import Reader
V1 = Path(sys.argv[1])
V2 = Path(sys.argv[2])
MAP = {"/Velodyne1_SCAN": "/velodyne/points", "/ouster/points": "/ouster/points", "/ouster/imu": "/ouster/imu",
"/ouster/reflec_image": "/ouster/reflec_image", "/stereo_camera/left/image_raw": "/stereo_camera/left/image_raw",
"/stereo_camera/right/image_raw": "/stereo_camera/right/image_raw"}
with Reader(V1) as r:
n1 = {}
for c in r.connections:
n1[c.topic] = n1.get(c.topic, 0) + c.msgcount
md = yaml.safe_load(open(V2 / "metadata.yaml"))["rosbag2_bagfile_information"]
n2 = {t["topic_metadata"]["name"]: t["message_count"] for t in md["topics_with_message_count"]}
ok = True
for a, b in MAP.items():
good = n1.get(a, 0) == n2.get(b, 0)
ok &= good
print(f"{'OK ' if good else 'BAD'} {a} {n1.get(a, 0)} -> {b} {n2.get(b, -1)}")
for side in ("left", "right"):
good = n2.get(f"/stereo_camera/{side}/camera_info", 0) == n2.get(f"/stereo_camera/{side}/image_raw", 0)
ok &= good
print(f"{'OK ' if good else 'BAD'} camera_info {side} == images")
nf = len(md["relative_file_paths"])
good = n2.get("/tf_static") == nf
ok &= good
print(f"{'OK ' if good else 'BAD'} /tf_static once per file ({nf} files)")
res = subprocess.run(["bash", "-c", f"source /opt/ros/jazzy/setup.bash && ros2 bag info '{V2}'"], capture_output=True, text=True)
good = res.returncode == 0
ok &= good
print(f"{'OK ' if good else 'BAD'} ros2 bag info")
print("VERIFY", "PASS" if ok else "FAIL", V2.name, f"{sum(f.stat().st_size for f in V2.glob('*.mcap')) / 1e9:.2f} GB")
sys.exit(0 if ok else 1)