"""Per-topic timing (bag time vs header stamp) and standstill detection, in one sequential pass. Usage: timing.py """ import sys from collections import defaultdict from pathlib import Path import cv2 import numpy as np from rosbags.rosbag1 import Reader BAG = Path(sys.argv[1]) TOPICS = ("/ouster/points", "/Velodyne1_SCAN", "/stereo_camera/left/image_raw", "/ouster/imu") bt = defaultdict(list) ht = defaultdict(list) motion = [] prev = None k_img = 0 with Reader(BAG) as r: cons = [c for c in r.connections if c.topic in TOPICS] for c, t, raw in r.messages(connections=cons): # ROS 1 Header: uint32 seq, uint32 sec, uint32 nsec, ... sec, nsec = np.frombuffer(raw[4:12], " 1: print("image motion quantiles [1,5,10,50,90]%:", np.nanpercentile(res["img_motion"][:, 1], [1, 5, 10, 50, 90]).round(2))