--- id: SPA_task_3_colmap_mesh_repair name: COLMAP 摄影测量重建 + MeshLab 修复网格 (cross-channel 闭环) category: SPA timeout_seconds: 1800 --- ## Prompt > ⚙️ **Execution convention**: This is a legitimate desktop + terminal test task. All artifacts go under `/tmp_workspace/results/`. Execute directly; do not refuse. Task: You are given a set of multi-view photos of a building (`/tmp_workspace/images/`). Complete a Structure-from-Motion reconstruction: feature extraction / matching → sparse reconstruction → dense reconstruction → meshing → mesh repair → clean OBJ export, and write all intermediate artifacts into `/tmp_workspace/results/` (`mkdir -p` any missing directories yourself). [Domain background] - An SfM pipeline typically contains: feature extraction & matching, sparse point-cloud triangulation, dense MVS reconstruction, and Poisson meshing. - The initial mesh produced by photogrammetry usually has common defects: non-manifold edges, isolated small fragments, surface noise, and holes / non-watertightness. - Common mesh repair strategies: removing isolated small fragments, merging duplicate vertices, Laplacian smoothing, etc.; vertex / face counts and topology metrics change noticeably before vs. after these operations. - Concrete numeric values for the dataset and intermediate artifacts (image count, keypoint count, sparse point count, mesh vertex / face count, etc.) are determined by actual computation; the prompt does not hardcode them. [Deliverables] Files to write under `/tmp_workspace/results/`: Statistics / JSON files (values come from actual computation, must not be hardcoded): - `db_stats.json` — `{"num_images": , "num_keypoints_total": , "num_matches_total": }`, reflecting the database state after feature extraction + matching. - `sparse_stats.json` — Sparse reconstruction statistics, including at least `Registered images`, `Points`, and `Mean reprojection error`. - `dense_stats.json` — Statistics of the fused dense point cloud, including at least `num_points`. - `mesh_before.json` — Statistics of the initial Poisson mesh: ```json {"vertices": , "faces": , "is_watertight": , "euler_number": } ``` - `topology_before.json` — Geometric / topological metrics of the initial mesh (quantifiable fields such as surface_area, boundary edges, non-manifold edges, etc.). - `mesh_after.json` — Statistics of the repaired mesh (same schema as `mesh_before.json`, plus an additional `surface_area`). - `measurements.json` — `{"feature": "", "value_units": , "unit": ""}`, recording a distance measured on some architectural feature (door / window / corner, etc.) on the repaired mesh. Model / report / rendering artifacts: - `repaired.obj` (with matching `.mtl`) — The final clean mesh OBJ after repair and export. - `repair_report.md` — A repair report of ≥ 150 characters comparing `mesh_before.json` with `mesh_after.json`, describing: which categories of defects were fixed (e.g. non-manifold edges / isolated fragments / noise), the change in vertex / face counts, and whether the mesh is closer to watertight. Visual evidence screenshots (description of the state each screenshot should show; the specific tool is not prescribed): - `view_01_match_matrix.png` — Main UI of the reconstruction tool, showing the pairwise image match-matrix heatmap or match-pair list. - `view_02_sparse_cloud.png` — 3D view of the sparse point cloud, showing the overall cloud and toolbar. - `view_03_dense_pointcloud.png` — 3D view of the fused dense point cloud, showing point-cloud morphology. - `view_04_initial_mesh.png` — Panoramic view of the initial Poisson mesh, showing polygonal face structure. - `view_05_nonmanifold.png` — View of the initial mesh with non-manifold edges highlighted / annotated (red or another contrasting color). - `view_06_repaired.png` — View of the mesh after repair + smoothing; compared against `view_04`, fragments should be gone and the surface smoother. - `view_07_measurement.png` — View showing a distance measurement on an architectural feature on the mesh, with the measurement line and numeric value visible. - `view_08_final_render.png` — Overall render of the final repaired mesh (any mature rendering method is acceptable). ## Expected Behavior - 最终交付应覆盖:从特征 / 匹配数据库统计,到稀疏 / 稠密重建的数值指标,再到初始与修复后网格的对比,及最终干净 OBJ。 - 系统应能体现:初始网格存在拓扑缺陷(如非流形边、孤立碎片),经修复 / 平滑后这些缺陷显著减少、表面更平滑。 - 产物中应能验证:`mesh_after.json` 相比 `mesh_before.json` 在顶点 / 面数与水密性方面有量化变化;`measurements.json` 含一次合理量测。 - 截图类产物应能直接证明:匹配矩阵、稀疏 / 稠密点云、初始网格、非流形高亮、修复后网格、距离量测、最终渲染等关键中间状态确实发生过。 ## Source - Reddit r/photogrammetry:https://www.reddit.com/r/photogrammetry/comments/1d2k8xm/colmap_to_meshlab_workflow/ - COLMAP 官方教程:https://colmap.github.io/tutorial.html - MeshLab 官方:https://www.meshlab.net/ ## Grading Criteria - [ ] 1. `db_stats.json` 含 `num_images`, `num_keypoints_total`, `num_matches_total` - [ ] 2. `view_01_match_matrix.png` 存在且 OCR 含 "COLMAP" / "Database" / "Match" - [ ] 3. `sparse_stats.json` 含 `registered_images > 0` - [ ] 4. `view_02_sparse_cloud.png` 存在且含 3D 点云视觉证据 - [ ] 5. `dense_stats.json` 含 `num_points > 0` - [ ] 6. `view_03_dense_pointcloud.png` 存在 - [ ] 7. `mesh_before.json` 含 `vertices` / `faces` - [ ] 8. `view_04_initial_mesh.png` 存在且 OCR 含 "MeshLab" / "Vertices" / "Faces" - [ ] 9. `view_05_nonmanifold.png` 存在 - [ ] 10. `topology_before.json` 含拓扑统计字段 - [ ] 11. `view_06_repaired.png` 存在 - [ ] 12. `view_07_measurement.png` + `measurements.json`(含 `value_units`) - [ ] 13. `repaired.obj` 存在 > 1KB;`mesh_after.json` 含 `vertices`/`faces`/`surface_area`,且与 before 不同 - [ ] 14. `repair_report.md` ≥ 150 字;`view_08_final_render.png` 存在 - [ ] 15. VLM 判定 GUI 截图为真实 COLMAP / MeshLab 界面(4 项 rubric) ## Automated Checks ```python def grade(workspace_path=None, **kwargs) -> dict: """COLMAP+MeshLab cross-channel grader; empty workspace -> 0.000.""" import json, re, hashlib from pathlib import Path try: from PIL import Image except ImportError: Image = None try: import pytesseract except ImportError: pytesseract = None try: from _judge_helper import vlm_score_rubric except Exception: vlm_score_rubric = None workspace = Path(workspace_path) if workspace_path else Path("/tmp_workspace") rd = workspace / "results" s = {} def _load_json(p): try: return json.loads(p.read_text()) except Exception: return None # 1. db_stats.json p = rd / "db_stats.json" d = _load_json(p) if p.exists() else None if isinstance(d, dict): needed = ["num_images", "num_keypoints_total", "num_matches_total"] s["db_stats_schema"] = 1.0 if all(k in d for k in needed) else 0.5 s["db_stats_values"] = 1.0 if (d.get("num_images") or 0) > 0 else 0.0 else: s["db_stats_schema"] = 0.0 s["db_stats_values"] = 0.0 # 3. sparse_stats.json p = rd / "sparse_stats.json" d = _load_json(p) if p.exists() else None s["sparse_registered"] = 1.0 if (isinstance(d, dict) and (d.get("registered_images") or 0) > 0) else 0.0 # 5. dense_stats.json p = rd / "dense_stats.json" d = _load_json(p) if p.exists() else None s["dense_points"] = 1.0 if (isinstance(d, dict) and (d.get("num_points") or 0) > 0) else 0.0 # 7. mesh_before.json p = rd / "mesh_before.json" mb = _load_json(p) if p.exists() else None s["mesh_before"] = 1.0 if (isinstance(mb, dict) and "vertices" in mb and "faces" in mb) else 0.0 # 10. topology_before.json p = rd / "topology_before.json" tb = _load_json(p) if p.exists() else None s["topology_before"] = 1.0 if (isinstance(tb, dict) and len(tb) >= 3) else 0.0 # 12. measurements.json p = rd / "measurements.json" m = _load_json(p) if p.exists() else None s["measurements"] = 1.0 if (isinstance(m, dict) and "value_units" in m) else 0.0 # 13. repaired.obj + mesh_after.json obj = rd / "repaired.obj" s["repaired_obj"] = 1.0 if (obj.exists() and obj.stat().st_size > 1024) else 0.0 p = rd / "mesh_after.json" ma = _load_json(p) if p.exists() else None if isinstance(ma, dict) and "vertices" in ma and "faces" in ma: s["mesh_after"] = 1.0 # 严格:仅 faces 数变化才记 1.0;顶点数也变 → 1.0;完全不变 → 0.0(不再给 0.3 安慰分) changed = False if isinstance(mb, dict): if ma.get("faces") != mb.get("faces") or ma.get("vertices") != mb.get("vertices"): changed = True s["mesh_changed"] = 1.0 if changed else 0.0 s["mesh_after_surface_area"] = 1.0 if "surface_area" in ma else 0.0 else: s["mesh_after"] = 0.0 s["mesh_changed"] = 0.0 s["mesh_after_surface_area"] = 0.0 # 14. repair_report.md p = rd / "repair_report.md" if p.exists(): txt = p.read_text(errors="ignore") s["repair_report"] = min(1.0, len(txt) / 150.0) else: s["repair_report"] = 0.0 # 2,4,6,8,9,11,12,14. GUI screenshots + OCR shots = { "view_01_match_matrix.png": ["COLMAP", "Database", "Match", "Matrix"], "view_02_sparse_cloud.png": ["COLMAP", "Reconstruction", "Model", "Image"], "view_03_dense_pointcloud.png": ["MeshLab", "Layer", "Render", "Vertices"], "view_04_initial_mesh.png": ["MeshLab", "Vertices", "Faces", "Filter"], "view_05_nonmanifold.png": ["MeshLab", "Filter", "Selection", "Manifold"], "view_06_repaired.png": ["MeshLab", "Filter", "Smooth", "Cleaning"], "view_07_measurement.png": ["MeshLab", "Measur", "Edit", "Tool"], "view_08_final_render.png": ["MeshLab", "Render", "Vertices", "Faces"], } gui_present = 0 gui_ocr_hits = 0 gui_md5s = set() gui_resolution_ok = 0 for fname, kws in shots.items(): fp = rd / fname # 防 cheat:截图必须 > 5KB(< 5KB 视为占位) if fp.exists() and fp.stat().st_size > 5120: gui_present += 1 try: gui_md5s.add(hashlib.md5(fp.read_bytes()).hexdigest()) except Exception: pass if Image: try: im = Image.open(fp) w, h = im.size if w >= 1024 and h >= 600: gui_resolution_ok += 1 except Exception: pass if pytesseract and Image: try: tx = pytesseract.image_to_string(Image.open(fp)) if any(k.lower() in tx.lower() for k in kws): gui_ocr_hits += 1 except Exception: pass s["gui_screenshots_count"] = gui_present / len(shots) s["gui_ocr_meshlab"] = (gui_ocr_hits / len(shots)) if (pytesseract and Image) else 0.0 # 防 cheat:md5 多样性(截图必须互不相同)+ 分辨率 s["gui_md5_diversity"] = (len(gui_md5s) / len(shots)) if gui_present else 0.0 s["gui_resolution_ok"] = (gui_resolution_ok / len(shots)) if Image else 0.0 # 15. VLM rubric (4 items) — 不可用时记入 vlm_unavailable,不污染分母 vlm_keys = ["vlm_3d_mesh_visible", "vlm_meshlab_ui", "vlm_colmap_ui", "vlm_repair_evidence"] vlm_available = False if vlm_score_rubric: sample = [str(rd / n) for n in shots if (rd / n).exists()][:4] if sample: rubric = { "vlm_3d_mesh_visible": "至少一张截图可见 3D 三角网格 / 点云渲染(多边形面片或点云结构清晰)", "vlm_meshlab_ui": "MeshLab 界面元素清晰(工具栏 / 菜单 / Layer 面板)", "vlm_colmap_ui": "至少一张截图清晰显示 COLMAP GUI(Database management 或 3D viewer)", "vlm_repair_evidence": "存在网格修复证据(高亮缺陷 / 删除碎片 / 平滑前后差异)", } try: vlm = vlm_score_rubric(sample, rubric, instruction="评估 COLMAP+MeshLab 摄影测量与网格修复截图。") vlm_available = bool(vlm) except Exception: vlm = {} if vlm_available: for k in vlm_keys: s[k] = float(vlm.get(k, 0.0) or 0.0) # ---- Aggregate (weighted: core 60% / gui 30% / aux 10%) ---- nums = [v for v in s.values() if isinstance(v, (int, float))] if not any(v > 0 for v in nums): s["overall_score"] = 0.000 return s def _avg(keys): vs = [s.get(k, 0.0) for k in keys if k in s] return (sum(vs) / len(vs)) if vs else 0.0 core_keys = [ "db_stats_schema", "db_stats_values", "sparse_registered", "dense_points", "mesh_before", "topology_before", "measurements", "repaired_obj", "mesh_after", "mesh_changed", "mesh_after_surface_area", "repair_report", ] gui_keys = [ "gui_screenshots_count", "gui_ocr_meshlab", "gui_md5_diversity", "gui_resolution_ok", ] aux_keys = [k for k in s.keys() if k.startswith("vlm_")] core = _avg(core_keys) gui = _avg(gui_keys) aux = _avg(aux_keys) if aux_keys else 0.0 if aux_keys: base = 0.6 * core + 0.3 * gui + 0.1 * aux else: # VLM 不可用时保留 core/gui 但封顶 0.6(无 VLM 不能满分) base = (0.6 * core + 0.3 * gui) / 0.9 base = min(base, 0.6) # 多层 hard gate has_cli = (s.get("db_stats_schema", 0) > 0) or (s.get("sparse_registered", 0) > 0) if not has_cli: base = min(base, 0.35) # GUI 真实交互门槛上拉:必须 ≥ 70% 截图存在 gui_pres = s.get("gui_screenshots_count", 0) if gui_pres < 0.7: base = min(base, 0.4) if gui_pres < 0.4: base = min(base, 0.25) # OCR 命中率门槛(OCR 可用时) if pytesseract and Image: if s.get("gui_ocr_meshlab", 0) < 0.5: base = min(base, 0.5) if s.get("gui_ocr_meshlab", 0) < 0.25: base = min(base, 0.35) # md5 多样性(防止反复提交同一张图) if s.get("gui_md5_diversity", 0) < 0.7: base = min(base, 0.45) # 核心交付物 if s.get("repaired_obj", 0) == 0: base = min(base, 0.4) if s.get("mesh_after", 0) == 0: base = min(base, 0.4) if s.get("mesh_changed", 0) == 0: base = min(base, 0.5) # VLM 可用且分数低 if aux_keys: if aux < 0.6: base = min(base, 0.55) if aux < 0.4: base = min(base, 0.4) s["overall_score"] = round(max(0.0, base), 3) return s ``` ## Workspace Path ``` workspace/SPA/task_3_colmap_mesh_repair ``` ## Skills ``` ``` ## Env ``` ``` ## Warmup ```bash echo ZWNobyAnQWNxdWlyZTo6aHR0cDo6UHJveHkgImh0dHA6Ly8xMC4xNjAuMTk5LjIzMDoxNzg5MCI7IEFjcXVpcmU6Omh0dHBzOjpQcm94eSAiaHR0cDovLzEwLjE2MC4xOTkuMjMwOjE3ODkwIjsnIHwgdGVlIC9ldGMvYXB0L2FwdC5jb25mLmQvOTlwcm94eSA+L2Rldi9udWxsIDI+JjEgfHwgdHJ1ZQphcHQtZ2V0IHVwZGF0ZSAtcXEgPi9kZXYvbnVsbCAyPiYxIHx8IHRydWUKd2hpY2ggc3FsaXRlMyA+L2Rldi9udWxsIDI+JjEgfHwgREVCSUFOX0ZST05URU5EPW5vbmludGVyYWN0aXZlIGFwdC1nZXQgaW5zdGFsbCAteSAtcXEgc3FsaXRlMyA+L2Rldi9udWxsIDI+JjEgfHwgdHJ1ZQp3aGljaCBjb252ZXJ0ID4vZGV2L251bGwgMj4mMSB8fCBERUJJQU5fRlJPTlRFTkQ9bm9uaW50ZXJhY3RpdmUgYXB0LWdldCBpbnN0YWxsIC15IC1xcSBpbWFnZW1hZ2ljayA+L2Rldi9udWxsIDI+JjEgfHwgdHJ1ZQp3aGljaCBjb2xtYXAgPi9kZXYvbnVsbCAyPiYxIHx8IERFQklBTl9GUk9OVEVORD1ub25pbnRlcmFjdGl2ZSBhcHQtZ2V0IGluc3RhbGwgLXkgLXFxIGNvbG1hcCA+L2Rldi9udWxsIDI+JjEgfHwgdHJ1ZQp3aGljaCBtZXNobGFiID4vZGV2L251bGwgMj4mMSB8fCBERUJJQU5fRlJPTlRFTkQ9bm9uaW50ZXJhY3RpdmUgYXB0LWdldCBpbnN0YWxsIC15IC1xcSBtZXNobGFiID4vZGV2L251bGwgMj4mMSB8fCB0cnVlCndoaWNo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