Buckets:
| import csv | |
| import json | |
| import os | |
| import cv2 | |
| import numpy as np | |
| ROOT = "/root/bdmc_pipeline" | |
| FRAMES_DIR = f"{ROOT}/frames" | |
| MASKS_DIR = f"{ROOT}/masks/road_surface" | |
| DEPTH_DIR = f"{ROOT}/depth" | |
| OUT_DIR = f"{ROOT}/outputs" | |
| FPS = 5.0 | |
| H, W = 1920, 1080 | |
| FOV_LONG_DEG = 72.0 | |
| fx = fy = H / (2 * np.tan(np.radians(FOV_LONG_DEG / 2))) | |
| N_FRAMES = 300 | |
| os.makedirs(OUT_DIR, exist_ok=True) | |
| defects = [] | |
| defects_path = f"{OUT_DIR}/defects_fused.csv" | |
| if os.path.exists(defects_path): | |
| with open(defects_path) as f: | |
| reader = csv.DictReader(f) | |
| for row in reader: | |
| if row.get("confidence") in ("agree", "partial"): | |
| defects.append(row) | |
| devmaps = None | |
| devmaps_path = f"{OUT_DIR}/devmaps_small.npz" | |
| if os.path.exists(devmaps_path): | |
| z = np.load(devmaps_path) | |
| devmaps = z["dev"].astype(np.float32) | |
| devmaps = (devmaps - 128.0) / 1000.0 | |
| fourcc = cv2.VideoWriter_fourcc(*"mp4v") | |
| out_path = f"{OUT_DIR}/overlay_60s.mp4" | |
| writer = cv2.VideoWriter(out_path, fourcc, FPS, (W, H)) | |
| noise_floor = {} | |
| if os.path.exists(f"{OUT_DIR}/phase3_summary.json"): | |
| with open(f"{OUT_DIR}/phase3_summary.json") as f: | |
| nf = json.load(f) | |
| noise_floor = { | |
| "tile_sigma_cm": nf.get("tile_sigma_median_cm", 0), | |
| "threshold_cm": nf.get("threshold_used_cm", 0), | |
| } | |
| for i in range(1, N_FRAMES + 1): | |
| frame = cv2.imread(f"{FRAMES_DIR}/f_{i:04d}.jpg") | |
| if frame is None: | |
| continue | |
| mask = cv2.imread(f"{MASKS_DIR}/f_{i:04d}.png", 0) | |
| if mask is not None: | |
| overlay = frame.copy() | |
| overlay[mask > 127] = (overlay[mask > 127] * 0.6 + np.array([0, 80, 0]) * 0.4).astype(np.uint8) | |
| cv2.addWeighted(overlay, 0.7, frame, 0.3, 0, frame) | |
| for defect in defects: | |
| cx, cy = 0, 0 | |
| centroid = defect.get("centroid_px", "") | |
| if isinstance(centroid, str): | |
| parts = centroid.replace("[", "").replace("]", "").split() | |
| if len(parts) >= 2: | |
| cx, cy = float(parts[0]), float(parts[1]) | |
| elif isinstance(centroid, list): | |
| cx, cy = float(centroid[0]), float(centroid[1]) | |
| first_f = int(defect.get("first_frame", 0)) | |
| dur = int(defect.get("duration_frames", 0)) | |
| if first_f <= i <= first_f + dur: | |
| cv2.circle(frame, (int(cx), int(cy)), 15, (0, 0, 255), 2) | |
| cv2.putText(frame, f"{defect.get('peak_dev_cm', '?')}cm", | |
| (int(cx) - 30, int(cy) - 20), | |
| cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2) | |
| t_sec = (i - 1) / FPS | |
| hud_lines = [ | |
| f"Frame {i}/{N_FRAMES} | t={t_sec:.1f}s", | |
| ] | |
| if noise_floor: | |
| hud_lines.append(f"Sigma={noise_floor.get('tile_sigma_cm', 0):.1f}cm Thresh={noise_floor.get('threshold_cm', 0):.1f}cm") | |
| hud_lines.append(f"Defects confirmed: {len(defects)}") | |
| y0 = 30 | |
| for line in hud_lines: | |
| cv2.putText(frame, line, (15, y0), | |
| cv2.FONT_HERSHEY_SIMPLEX, 0.65, (255, 255, 255), 2) | |
| cv2.putText(frame, line, (15, y0), | |
| cv2.FONT_HERSHEY_SIMPLEX, 0.65, (0, 200, 0), 1) | |
| y0 += 28 | |
| writer.write(frame) | |
| writer.release() | |
| print(f"Phase 4 render complete: {out_path}") | |
| print(f" {N_FRAMES} frames rendered, {len(defects)} defect overlays") | |
Xet Storage Details
- Size:
- 3.29 kB
- Xet hash:
- bad840b2c03d4c0a98ca35d0ca349d50dd00a2ea21c4a3877c78e9a2f5386a40
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.