malakhovks commited on
Commit
89a2d44
·
verified ·
1 Parent(s): e0c2ca6

Publish supplementary reproducibility package for manuscript A01260048

Browse files
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ *.docx
2
+ __pycache__/
3
+ *.py[cod]
4
+ .venv/
5
+ .hf/
LICENSE-CODE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
LICENSE-DATA ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Creative Commons Attribution 4.0 International (CC BY 4.0)
2
+
3
+ Copyright (c) 2026 The authors
4
+
5
+ The results, images, figures, and documentation in this repository are
6
+ licensed under the Creative Commons Attribution 4.0 International License.
7
+ You may share and adapt these materials for any purpose, provided appropriate
8
+ credit is given and changes are indicated.
9
+
10
+ License deed and legal code:
11
+ https://creativecommons.org/licenses/by/4.0/
README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pretty_name: "Supplementary Package — Teaching Feature-Based 2D-to-3D Reconstruction"
3
+ language:
4
+ - en
5
+ license:
6
+ - mit
7
+ - cc-by-4.0
8
+ tags:
9
+ - opencv
10
+ - structure-from-motion
11
+ - 3d-reconstruction
12
+ - computer-science-education
13
+ - reproducibility
14
+ ---
15
+
16
+ # Supplementary Reproducibility Package — Manuscript A01260048
17
+
18
+ This package accompanies the article “Teaching Feature-Based 2D-to-3D Reconstruction for Metaverse-Oriented Content Generation: An OpenCV Structure-from-Motion Methodology for Computer Science Students.” It provides the executable OpenCV benchmark, pinned dependencies, machine-readable results, representative scene images, and figure sources used in the study.
19
+
20
+ ## Contents
21
+
22
+ - `benchmark_sfm.py`: deterministic scene generation, feature extraction, matching, pose recovery, triangulation, quality measurement, and figure generation.
23
+ - `requirements.txt`: pinned Python package versions.
24
+ - `media/image2.jpg`: historical five-view sparse-output image used in the visual comparison.
25
+ - `benchmark_output/benchmark_results.json`: machine-readable results for all three scenes and all three image-count conditions.
26
+ - `benchmark_output/*_views.png`: representative input views.
27
+ - `benchmark_output/figure1_density_comparison.png`, `figure2_scene_sequences.png`, and `figure3_accuracy_diagnostics.png`: benchmark-generated source images for Figures 1–3.
28
+ - `benchmark_output/figure4_c4_dynamic_bw.png`: publication-resolution black-and-white C4 Dynamic diagram used as Figure 4.
29
+ - `benchmark_output/figure4_c4_dynamic_bw.svg`: editable vector source for Figure 4.
30
+ - `benchmark_output/artifact24_points.npz`: saved point/color arrays for the 24-view curved-artifact condition.
31
+
32
+ ## Tested environment
33
+
34
+ - Python 3.12.13
35
+ - Linux, CPU-only execution
36
+ - OpenCV 4.11.0
37
+ - NumPy 2.5.1
38
+
39
+ ## Reproduce the benchmark
40
+
41
+ From the archive root, create an isolated Python environment and run:
42
+
43
+ ```bash
44
+ python -m pip install -r requirements.txt
45
+ python benchmark_sfm.py
46
+ ```
47
+
48
+ The script writes results and benchmark-generated Figures 1–3 to `benchmark_output/`. Figure 4 is a manually authored C4 architecture diagram supplied in PNG and SVG formats. The fixed OpenCV random seed is `20260718`; the remaining reconstruction parameters are declared in the script.
49
+
50
+ ## Expected validation range
51
+
52
+ The included JSON file is the authoritative output from the reported run. Small runtime differences across machines are expected. Camera registration, inlier ratios, reprojection RMSE values, and filtered point counts should remain consistent with the pinned dependencies and seed.
53
+
54
+ No learner or classroom observations are contained in this package.
55
+
56
+ ## License
57
+
58
+ `benchmark_sfm.py` is released under the MIT License; see `LICENSE-CODE`. Results, images, figures, and documentation are released under Creative Commons Attribution 4.0 International (CC BY 4.0); see `LICENSE-DATA`. Third-party Python dependencies retain their respective licenses.
benchmark_output/artifact24_points.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9b9a58f1c8f373498b480e4e869638bc239f04b3d1e3150462f8d916149959e
3
+ size 377099
benchmark_output/artifact_views.png ADDED

Git LFS Details

  • SHA256: 482e3487e6e162761302a8fb215e77a58321bdfd52fe003c4bc54bd61024b081
  • Pointer size: 131 Bytes
  • Size of remote file: 337 kB
benchmark_output/benchmark_results.json ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "registered_cameras": 12,
4
+ "keypoints_mean": 2600.0,
5
+ "raw_matches": 28600,
6
+ "ratio_matches": 15432,
7
+ "inliers": 9765,
8
+ "inlier_ratio": 0.6226537041067123,
9
+ "reprojection_rmse": 0.4322213866979627,
10
+ "rotation_error_deg": 6.8455868058288,
11
+ "translation_error_deg": 63.584671090431364,
12
+ "runtime_ms": {
13
+ "orb": 236.40612499730196,
14
+ "matching": 134.63996500649955,
15
+ "pose_triangulation": 139.88465400325367,
16
+ "total": 510.9307440070552
17
+ },
18
+ "scene": "device",
19
+ "views": 12,
20
+ "points": 8024,
21
+ "precision_delta_0_12": 0.0,
22
+ "median_surface_distance": 1.9785956349640763
23
+ },
24
+ {
25
+ "registered_cameras": 24,
26
+ "keypoints_mean": 2600.0,
27
+ "raw_matches": 59800,
28
+ "ratio_matches": 35496,
29
+ "inliers": 16709,
30
+ "inlier_ratio": 0.46561610853492136,
31
+ "reprojection_rmse": 0.38059813727625935,
32
+ "rotation_error_deg": 3.183869704907662,
33
+ "translation_error_deg": 76.01394439961426,
34
+ "runtime_ms": {
35
+ "orb": 422.15879199648043,
36
+ "matching": 346.8081460086978,
37
+ "pose_triangulation": 301.87341801502043,
38
+ "total": 1070.8403560201987
39
+ },
40
+ "scene": "device",
41
+ "views": 24,
42
+ "points": 13133,
43
+ "precision_delta_0_12": 0.0,
44
+ "median_surface_distance": 6.085733261710223
45
+ },
46
+ {
47
+ "registered_cameras": 48,
48
+ "keypoints_mean": 2600.0,
49
+ "raw_matches": 122200,
50
+ "ratio_matches": 76970,
51
+ "inliers": 5034,
52
+ "inlier_ratio": 0.06652679915143633,
53
+ "reprojection_rmse": 0.36520244983341876,
54
+ "rotation_error_deg": 1.5688838898871273,
55
+ "translation_error_deg": 179.27659461462576,
56
+ "runtime_ms": {
57
+ "orb": 856.7539009964094,
58
+ "matching": 649.6090320142685,
59
+ "pose_triangulation": 605.8213570067892,
60
+ "total": 2112.184290017467
61
+ },
62
+ "scene": "device",
63
+ "views": 48,
64
+ "points": 3842,
65
+ "precision_delta_0_12": 0.0,
66
+ "median_surface_distance": 1.6485339450088428
67
+ },
68
+ {
69
+ "registered_cameras": 12,
70
+ "keypoints_mean": 2600.0,
71
+ "raw_matches": 28600,
72
+ "ratio_matches": 14320,
73
+ "inliers": 12070,
74
+ "inlier_ratio": 0.8453835568109237,
75
+ "reprojection_rmse": 0.4288368860824866,
76
+ "rotation_error_deg": 2.029805384881694,
77
+ "translation_error_deg": 11.282220945828193,
78
+ "runtime_ms": {
79
+ "orb": 256.67538400011836,
80
+ "matching": 145.64748899283586,
81
+ "pose_triangulation": 131.82846899871947,
82
+ "total": 534.1513419916737
83
+ },
84
+ "scene": "facade",
85
+ "views": 12,
86
+ "points": 10531,
87
+ "precision_delta_0_12": 0.0020890703636881587,
88
+ "median_surface_distance": 0.8723467244517173
89
+ },
90
+ {
91
+ "registered_cameras": 24,
92
+ "keypoints_mean": 2600.0,
93
+ "raw_matches": 59800,
94
+ "ratio_matches": 34943,
95
+ "inliers": 17803,
96
+ "inlier_ratio": 0.5128965566383472,
97
+ "reprojection_rmse": 0.4197560697411765,
98
+ "rotation_error_deg": 2.7803740609035046,
99
+ "translation_error_deg": 43.368639381236825,
100
+ "runtime_ms": {
101
+ "orb": 492.1730679998291,
102
+ "matching": 342.98218201001873,
103
+ "pose_triangulation": 288.1672420189716,
104
+ "total": 1123.3224920288194
105
+ },
106
+ "scene": "facade",
107
+ "views": 24,
108
+ "points": 16154,
109
+ "precision_delta_0_12": 0.07929924476909744,
110
+ "median_surface_distance": 1.993044582509977
111
+ },
112
+ {
113
+ "registered_cameras": 48,
114
+ "keypoints_mean": 2600.0,
115
+ "raw_matches": 122200,
116
+ "ratio_matches": 77108,
117
+ "inliers": 17221,
118
+ "inlier_ratio": 0.2209172176570936,
119
+ "reprojection_rmse": 0.3593112355974764,
120
+ "rotation_error_deg": 1.460584358474685,
121
+ "translation_error_deg": 78.32880820779788,
122
+ "runtime_ms": {
123
+ "orb": 1016.7356340025435,
124
+ "matching": 557.4353289921419,
125
+ "pose_triangulation": 600.9095129847992,
126
+ "total": 2175.0804759794846
127
+ },
128
+ "scene": "facade",
129
+ "views": 48,
130
+ "points": 14104,
131
+ "precision_delta_0_12": 0.0007090187180941577,
132
+ "median_surface_distance": 3.424638604424743
133
+ },
134
+ {
135
+ "registered_cameras": 12,
136
+ "keypoints_mean": 2600.0,
137
+ "raw_matches": 28600,
138
+ "ratio_matches": 12712,
139
+ "inliers": 11357,
140
+ "inlier_ratio": 0.8931136606229089,
141
+ "reprojection_rmse": 0.4358554817758148,
142
+ "rotation_error_deg": 2.5561843583095962,
143
+ "translation_error_deg": 2.554068329589189,
144
+ "runtime_ms": {
145
+ "orb": 229.56651500135195,
146
+ "matching": 125.51675498252735,
147
+ "pose_triangulation": 135.51045801432338,
148
+ "total": 490.59372799820267
149
+ },
150
+ "scene": "artifact",
151
+ "views": 12,
152
+ "points": 8930,
153
+ "precision_delta_0_12": 0.22015677491601343,
154
+ "median_surface_distance": 0.6121669461749182
155
+ },
156
+ {
157
+ "registered_cameras": 24,
158
+ "keypoints_mean": 2600.0,
159
+ "raw_matches": 59800,
160
+ "ratio_matches": 31402,
161
+ "inliers": 17805,
162
+ "inlier_ratio": 0.5661154398091268,
163
+ "reprojection_rmse": 0.404410029562593,
164
+ "rotation_error_deg": 2.1245791662147635,
165
+ "translation_error_deg": 5.4900199920773645,
166
+ "runtime_ms": {
167
+ "orb": 438.84134899417404,
168
+ "matching": 299.5004460171913,
169
+ "pose_triangulation": 280.9564260096522,
170
+ "total": 1019.2982210210175
171
+ },
172
+ "scene": "artifact",
173
+ "views": 24,
174
+ "points": 13883,
175
+ "precision_delta_0_12": 0.11575307930562559,
176
+ "median_surface_distance": 0.9705539843488513
177
+ },
178
+ {
179
+ "registered_cameras": 48,
180
+ "keypoints_mean": 2600.0,
181
+ "raw_matches": 122200,
182
+ "ratio_matches": 70186,
183
+ "inliers": 8697,
184
+ "inlier_ratio": 0.12489082063889277,
185
+ "reprojection_rmse": 0.34259139245563164,
186
+ "rotation_error_deg": 1.4468085108818491,
187
+ "translation_error_deg": 90.29411956576278,
188
+ "runtime_ms": {
189
+ "orb": 887.5838599997223,
190
+ "matching": 660.4910300084157,
191
+ "pose_triangulation": 604.5852350071073,
192
+ "total": 2152.6601250152453
193
+ },
194
+ "scene": "artifact",
195
+ "views": 48,
196
+ "points": 7822,
197
+ "precision_delta_0_12": 0.07299923293275377,
198
+ "median_surface_distance": 0.7326662410483766
199
+ }
200
+ ]
benchmark_output/device_views.png ADDED

Git LFS Details

  • SHA256: 34414f45abbde09b2250b90fd5d6eeb1194f7c43aadc492d6960df22bbcacfde
  • Pointer size: 131 Bytes
  • Size of remote file: 301 kB
benchmark_output/facade_views.png ADDED

Git LFS Details

  • SHA256: 2094ec75e00c572d50a7e89e5d8f2286a2c2805790f288a26aa0862cf4747fd0
  • Pointer size: 131 Bytes
  • Size of remote file: 367 kB
benchmark_output/figure1_density_comparison.png ADDED

Git LFS Details

  • SHA256: a7671b467da0c9a55b26f4b49ab4c76a0d20456b8923dc0ac7ddbe0a95ffe6a7
  • Pointer size: 131 Bytes
  • Size of remote file: 838 kB
benchmark_output/figure2_scene_sequences.png ADDED

Git LFS Details

  • SHA256: 7bb4a105824bf6ba1834061f5eafd2e1b83084ff696b6d21a28e6c8cf6ed6bcb
  • Pointer size: 132 Bytes
  • Size of remote file: 2.86 MB
benchmark_output/figure3_accuracy_diagnostics.png ADDED

Git LFS Details

  • SHA256: cdae04f51d247d78e358073725d3c55c81430e4e4c18ab519e3de88adaaf7b00
  • Pointer size: 131 Bytes
  • Size of remote file: 190 kB
benchmark_output/figure4_c4_dynamic_bw.png ADDED

Git LFS Details

  • SHA256: ff332f5a9c918ccc222ea04455f5ac36ffd4d7492cc7ef75326f7031c436e55b
  • Pointer size: 131 Bytes
  • Size of remote file: 434 kB
benchmark_output/figure4_c4_dynamic_bw.svg ADDED
benchmark_sfm.py ADDED
@@ -0,0 +1,469 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import math
5
+ import os
6
+ import time
7
+ from dataclasses import dataclass
8
+ from pathlib import Path
9
+
10
+ import cv2
11
+ import matplotlib
12
+
13
+ matplotlib.use("Agg")
14
+ import matplotlib.pyplot as plt
15
+ import numpy as np
16
+ from scipy.spatial import cKDTree
17
+
18
+
19
+ ROOT = Path(__file__).resolve().parent
20
+ OUT = ROOT / "benchmark_output"
21
+ OUT.mkdir(parents=True, exist_ok=True)
22
+
23
+ WIDTH, HEIGHT = 1280, 720
24
+ K = np.array([[980.0, 0.0, WIDTH / 2], [0.0, 980.0, HEIGHT / 2], [0.0, 0.0, 1.0]])
25
+ cv2.setRNGSeed(20260718)
26
+
27
+
28
+ @dataclass
29
+ class Plane:
30
+ corners: np.ndarray
31
+ texture: np.ndarray
32
+
33
+
34
+ def texture(seed: int, label: str, size: int = 520) -> np.ndarray:
35
+ rng = np.random.default_rng(seed)
36
+ img = np.full((size, size, 3), 215, np.uint8)
37
+ noise = rng.normal(0, 24, img.shape[:2]).astype(np.int16)
38
+ for c in range(3):
39
+ img[:, :, c] = np.clip(img[:, :, c].astype(np.int16) + noise, 0, 255)
40
+ for _ in range(110):
41
+ color = tuple(int(v) for v in rng.integers(20, 235, 3))
42
+ p1 = tuple(int(v) for v in rng.integers(0, size, 2))
43
+ if rng.random() < 0.5:
44
+ p2 = tuple(int(v) for v in rng.integers(0, size, 2))
45
+ cv2.line(img, p1, p2, color, int(rng.integers(1, 5)), cv2.LINE_AA)
46
+ else:
47
+ cv2.circle(img, p1, int(rng.integers(3, 24)), color, -1, cv2.LINE_AA)
48
+ for y in range(55, size, 85):
49
+ cv2.putText(img, f"{label}-{y//5}", (20, y), cv2.FONT_HERSHEY_SIMPLEX, 0.72,
50
+ (20, 20, 20), 2, cv2.LINE_AA)
51
+ return img
52
+
53
+
54
+ def quad(x0, x1, y0, y1, z: float) -> np.ndarray:
55
+ return np.array([[x0, y1, z], [x1, y1, z], [x1, y0, z], [x0, y0, z]], np.float64)
56
+
57
+
58
+ def scene_planes(name: str) -> list[Plane]:
59
+ if name == "device":
60
+ return [
61
+ Plane(quad(-0.95, 0.95, -0.66, 0.66, 0.42), texture(11, "front")),
62
+ Plane(np.array([[0.95, 0.66, 0.42], [0.95, 0.66, -0.46],
63
+ [0.95, -0.66, -0.46], [0.95, -0.66, 0.42]]), texture(12, "right")),
64
+ Plane(np.array([[-0.95, 0.66, -0.46], [-0.95, 0.66, 0.42],
65
+ [-0.95, -0.66, 0.42], [-0.95, -0.66, -0.46]]), texture(13, "left")),
66
+ Plane(np.array([[-0.95, 0.66, -0.46], [0.95, 0.66, -0.46],
67
+ [0.95, 0.66, 0.42], [-0.95, 0.66, 0.42]]), texture(14, "top")),
68
+ ]
69
+ if name == "facade":
70
+ planes = [Plane(quad(-1.45, 1.45, -0.95, 0.95, 0.0), texture(21, "facade"))]
71
+ for iy, y in enumerate([-0.52, 0.15, 0.67]):
72
+ for ix, x in enumerate([-0.92, -0.3, 0.32, 0.94]):
73
+ planes.append(Plane(quad(x - 0.18, x + 0.18, y - 0.17, y + 0.17, 0.09),
74
+ texture(100 + iy * 10 + ix, "window", 220)))
75
+ return planes
76
+ if name == "artifact":
77
+ planes = []
78
+ radius = 0.88
79
+ sides = 10
80
+ for i in range(sides):
81
+ a0 = 2 * math.pi * i / sides
82
+ a1 = 2 * math.pi * (i + 1) / sides
83
+ p0 = np.array([radius * math.sin(a0), -0.83, radius * math.cos(a0)])
84
+ p1 = np.array([radius * math.sin(a1), -0.83, radius * math.cos(a1)])
85
+ p2 = p1.copy(); p2[1] = 0.83
86
+ p3 = p0.copy(); p3[1] = 0.83
87
+ planes.append(Plane(np.vstack([p3, p2, p1, p0]), texture(40 + i, f"side{i}", 300)))
88
+ return planes
89
+ raise ValueError(name)
90
+
91
+
92
+ def look_at(theta_deg: float, radius: float = 4.2) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
93
+ theta = math.radians(theta_deg)
94
+ C = np.array([radius * math.sin(theta), 0.10, radius * math.cos(theta)], np.float64)
95
+ target = np.array([0.0, 0.0, 0.0])
96
+ forward = target - C
97
+ forward /= np.linalg.norm(forward)
98
+ up_world = np.array([0.0, 1.0, 0.0])
99
+ right = np.cross(forward, up_world)
100
+ right /= np.linalg.norm(right)
101
+ up = np.cross(right, forward)
102
+ R = np.vstack([right, -up, forward])
103
+ t = -R @ C
104
+ return R, t, C
105
+
106
+
107
+ def project(points: np.ndarray, R: np.ndarray, t: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
108
+ cam = (R @ points.T).T + t
109
+ pix_h = (K @ cam.T).T
110
+ pix = pix_h[:, :2] / pix_h[:, 2:3]
111
+ return pix, cam[:, 2]
112
+
113
+
114
+ def render(name: str, theta: float, idx: int) -> tuple[np.ndarray, tuple[np.ndarray, np.ndarray]]:
115
+ R, t, _ = look_at(theta)
116
+ bg = np.zeros((HEIGHT, WIDTH, 3), np.uint8)
117
+ yy = np.linspace(0, 1, HEIGHT, dtype=np.float32)[:, None]
118
+ base = 232 - (yy * 28)
119
+ bg[:] = np.repeat(base, WIDTH, axis=1)[:, :, None]
120
+ planes = []
121
+ for pl in scene_planes(name):
122
+ dst, depth = project(pl.corners, R, t)
123
+ if np.any(depth <= 0.1):
124
+ continue
125
+ center_depth = float(np.mean(depth))
126
+ planes.append((center_depth, pl, dst))
127
+ planes.sort(reverse=True, key=lambda x: x[0])
128
+ for _, pl, dst in planes:
129
+ h, w = pl.texture.shape[:2]
130
+ src = np.array([[0, 0], [w - 1, 0], [w - 1, h - 1], [0, h - 1]], np.float32)
131
+ Hm = cv2.getPerspectiveTransform(src, dst.astype(np.float32))
132
+ warped = cv2.warpPerspective(pl.texture, Hm, (WIDTH, HEIGHT), flags=cv2.INTER_LINEAR)
133
+ mask = cv2.warpPerspective(np.full((h, w), 255, np.uint8), Hm, (WIDTH, HEIGHT))
134
+ bg[mask > 0] = warped[mask > 0]
135
+ rng = np.random.default_rng(8000 + idx)
136
+ noise = rng.normal(0, 1.8, bg.shape).astype(np.int16)
137
+ bg = np.clip(bg.astype(np.int16) + noise, 0, 255).astype(np.uint8)
138
+ return bg, (R, t)
139
+
140
+
141
+ def sample_surface(name: str, per_plane: int = 9000) -> np.ndarray:
142
+ rng = np.random.default_rng(1200 + len(name))
143
+ pts = []
144
+ for pl in scene_planes(name):
145
+ u = rng.random(per_plane)
146
+ v = rng.random(per_plane)
147
+ p = ((1-u)[:, None] * (1-v)[:, None] * pl.corners[0] +
148
+ u[:, None] * (1-v)[:, None] * pl.corners[1] +
149
+ u[:, None] * v[:, None] * pl.corners[2] +
150
+ (1-u)[:, None] * v[:, None] * pl.corners[3])
151
+ pts.append(p)
152
+ return np.vstack(pts)
153
+
154
+
155
+ def rotation_error(R_est: np.ndarray, R_gt: np.ndarray) -> float:
156
+ c = (np.trace(R_gt.T @ R_est) - 1.0) / 2.0
157
+ return math.degrees(math.acos(float(np.clip(c, -1, 1))))
158
+
159
+
160
+ def direction_error(t_est: np.ndarray, t_gt: np.ndarray) -> float:
161
+ a = t_est.ravel() / np.linalg.norm(t_est)
162
+ b = t_gt.ravel() / np.linalg.norm(t_gt)
163
+ c = float(np.clip(np.dot(a, b), -1, 1))
164
+ return math.degrees(math.acos(c))
165
+
166
+
167
+ def voxel_reduce(points: np.ndarray, colors: np.ndarray, voxel: float = 0.018):
168
+ if len(points) == 0:
169
+ return points, colors
170
+ q = np.floor(points / voxel).astype(np.int64)
171
+ _, idx = np.unique(q, axis=0, return_index=True)
172
+ return points[idx], colors[idx]
173
+
174
+
175
+ def reconstruct(images: list[np.ndarray], gt_poses: list[tuple[np.ndarray, np.ndarray]], dense_track=False):
176
+ orb = cv2.ORB_create(nfeatures=2600, scaleFactor=1.2, nlevels=8, edgeThreshold=31,
177
+ firstLevel=0, WTA_K=2, scoreType=cv2.ORB_HARRIS_SCORE,
178
+ patchSize=31, fastThreshold=20)
179
+ matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=False)
180
+ gray = [cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) for im in images]
181
+ t0 = time.perf_counter()
182
+ kd = [orb.detectAndCompute(g, None) for g in gray]
183
+ detect_ms = (time.perf_counter() - t0) * 1000
184
+ R_acc = np.eye(3)
185
+ t_acc = np.zeros(3)
186
+ poses = [(R_acc.copy(), t_acc.copy())]
187
+ all_pts, all_cols = [], []
188
+ inlier_ratios, repr_errors, rerrs, terrs = [], [], [], []
189
+ match_ms = 0.0
190
+ pose_ms = 0.0
191
+ successful = 1
192
+ raw_matches_total = 0
193
+ ratio_matches_total = 0
194
+ inliers_total = 0
195
+
196
+ for i in range(len(images) - 1):
197
+ kp1, d1 = kd[i]
198
+ kp2, d2 = kd[i+1]
199
+ if d1 is None or d2 is None:
200
+ poses.append((R_acc.copy(), t_acc.copy()))
201
+ continue
202
+ tm = time.perf_counter()
203
+ knn = matcher.knnMatch(d1, d2, k=2)
204
+ raw_matches_total += len(knn)
205
+ good = [m for m, n in knn if m.distance < 0.75 * n.distance]
206
+ match_ms += (time.perf_counter() - tm) * 1000
207
+ ratio_matches_total += len(good)
208
+ if len(good) < 12:
209
+ poses.append((R_acc.copy(), t_acc.copy()))
210
+ continue
211
+ p1 = np.float64([kp1[m.queryIdx].pt for m in good])
212
+ p2 = np.float64([kp2[m.trainIdx].pt for m in good])
213
+ tp = time.perf_counter()
214
+ E, mask = cv2.findEssentialMat(p1, p2, K, cv2.RANSAC, 0.999, 1.5)
215
+ if E is None:
216
+ poses.append((R_acc.copy(), t_acc.copy()))
217
+ continue
218
+ _, Rrel, trel, pose_mask = cv2.recoverPose(E, p1, p2, K, mask=mask)
219
+ pose_ms += (time.perf_counter() - tp) * 1000
220
+ keep = pose_mask.ravel() > 0
221
+ p1i, p2i = p1[keep], p2[keep]
222
+ inliers_total += int(np.sum(keep))
223
+ inlier_ratios.append(float(np.sum(keep) / max(len(good), 1)))
224
+
225
+ R1_gt, t1_gt = gt_poses[i]
226
+ R2_gt, t2_gt = gt_poses[i+1]
227
+ Rrel_gt = R2_gt @ R1_gt.T
228
+ trel_gt = t2_gt - Rrel_gt @ t1_gt
229
+ scale = np.linalg.norm(trel_gt)
230
+ rerrs.append(rotation_error(Rrel, Rrel_gt))
231
+ terrs.append(direction_error(trel, trel_gt))
232
+ R_next = Rrel @ R_acc
233
+ t_next = Rrel @ t_acc + trel.ravel() * scale
234
+ P1 = K @ np.hstack([R_acc, t_acc[:, None]])
235
+ P2 = K @ np.hstack([R_next, t_next[:, None]])
236
+ if len(p1i) >= 4:
237
+ Xh = cv2.triangulatePoints(P1, P2, p1i.T, p2i.T)
238
+ X = (Xh[:3] / Xh[3]).T
239
+ z1 = (R_acc @ X.T + t_acc[:, None])[2]
240
+ z2 = (R_next @ X.T + t_next[:, None])[2]
241
+ x1h = (P1 @ np.c_[X, np.ones(len(X))].T).T
242
+ x2h = (P2 @ np.c_[X, np.ones(len(X))].T).T
243
+ x1p = x1h[:, :2] / x1h[:, 2:3]
244
+ x2p = x2h[:, :2] / x2h[:, 2:3]
245
+ err = np.sqrt((np.sum((x1p-p1i)**2, axis=1) + np.sum((x2p-p2i)**2, axis=1))/2)
246
+ valid = np.isfinite(X).all(axis=1) & (z1 > 0) & (z2 > 0) & (err < 3.0)
247
+ X = X[valid]
248
+ err = err[valid]
249
+ pix = np.round(p1i[valid]).astype(int)
250
+ pix[:, 0] = np.clip(pix[:, 0], 0, WIDTH-1)
251
+ pix[:, 1] = np.clip(pix[:, 1], 0, HEIGHT-1)
252
+ cols = images[i][pix[:, 1], pix[:, 0], ::-1] / 255.0
253
+ all_pts.append(X); all_cols.append(cols)
254
+ repr_errors.extend(err.tolist())
255
+ R_acc, t_acc = R_next, t_next
256
+ poses.append((R_acc.copy(), t_acc.copy()))
257
+ successful += 1
258
+
259
+ if all_pts:
260
+ points = np.vstack(all_pts); colors = np.vstack(all_cols)
261
+ points, colors = voxel_reduce(points, colors)
262
+ else:
263
+ points = np.empty((0, 3)); colors = np.empty((0, 3))
264
+ return {
265
+ "points": points,
266
+ "colors": colors,
267
+ "registered_cameras": successful,
268
+ "keypoints_mean": float(np.mean([len(x[0]) for x in kd])),
269
+ "raw_matches": raw_matches_total,
270
+ "ratio_matches": ratio_matches_total,
271
+ "inliers": inliers_total,
272
+ "inlier_ratio": float(np.mean(inlier_ratios)) if inlier_ratios else float("nan"),
273
+ "reprojection_rmse": float(np.sqrt(np.mean(np.square(repr_errors)))) if repr_errors else float("nan"),
274
+ "rotation_error_deg": float(np.median(rerrs)) if rerrs else float("nan"),
275
+ "translation_error_deg": float(np.median(terrs)) if terrs else float("nan"),
276
+ "runtime_ms": {"orb": detect_ms, "matching": match_ms, "pose_triangulation": pose_ms,
277
+ "total": detect_ms + match_ms + pose_ms},
278
+ }
279
+
280
+
281
+ def geometric_precision(scene: str, points: np.ndarray, R0: np.ndarray, t0: np.ndarray, delta=0.12):
282
+ if len(points) == 0:
283
+ return 0.0, float("nan")
284
+ gt = sample_surface(scene)
285
+ gt0 = (R0 @ gt.T).T + t0
286
+ tree = cKDTree(gt0)
287
+ d, _ = tree.query(points, k=1)
288
+ return float(np.mean(d < delta)), float(np.median(d))
289
+
290
+
291
+ def plot_comparison(sparse_path: Path, result: dict, scene: str, R0: np.ndarray, t0: np.ndarray):
292
+ from PIL import Image
293
+ sparse = Image.open(sparse_path).convert("RGB")
294
+ pts = result["points"]
295
+ cols = result["colors"]
296
+ gt = sample_surface(scene, per_plane=2600)
297
+ gt0 = (R0 @ gt.T).T + t0
298
+ if len(pts):
299
+ surface_distance, _ = cKDTree(gt0).query(pts, k=1)
300
+ surface_consistent = surface_distance < 0.12
301
+ pts = pts[surface_consistent]
302
+ cols = cols[surface_consistent]
303
+ rng = np.random.default_rng(77)
304
+ if len(gt0) > 22000:
305
+ gt0 = gt0[rng.choice(len(gt0), 22000, replace=False)]
306
+ dense_cols = plt.cm.viridis((gt0[:, 1] - gt0[:, 1].min()) / (np.ptp(gt0[:, 1]) + 1e-9))[:, :3]
307
+
308
+ fig = plt.figure(figsize=(12.6, 4.1), dpi=220, facecolor="white")
309
+ ax0 = fig.add_subplot(1, 3, 1)
310
+ ax0.imshow(sparse)
311
+ ax0.set_title("(a) Original 5-view sparse output\n246 points", fontsize=10, weight="bold")
312
+ ax0.axis("off")
313
+ ax1 = fig.add_subplot(1, 3, 2, projection="3d")
314
+ if len(pts):
315
+ ax1.scatter(pts[:, 0], pts[:, 2], -pts[:, 1], c=cols, s=2.2, alpha=0.9)
316
+ ax1.set_title(f"(b) Expanded colored SfM output\n{len(pts):,} geometry-filtered points", fontsize=10, weight="bold")
317
+ ax2 = fig.add_subplot(1, 3, 3, projection="3d")
318
+ ax2.scatter(gt0[:, 0], gt0[:, 2], -gt0[:, 1], c=dense_cols, s=0.35, alpha=0.70)
319
+ ax2.set_title(f"(c) Dense reference handoff\n{len(gt0):,} surface samples", fontsize=10, weight="bold")
320
+ for ax in (ax1, ax2):
321
+ ax.view_init(elev=18, azim=-62)
322
+ ax.set_xlabel("x", fontsize=7); ax.set_ylabel("z", fontsize=7); ax.set_zlabel("y", fontsize=7)
323
+ ax.tick_params(labelsize=6, pad=0)
324
+ ax.set_box_aspect((1.35, 1, 0.85))
325
+ ax.grid(True, alpha=0.25)
326
+ fig.tight_layout(pad=1.3)
327
+ fig.savefig(OUT / "figure1_density_comparison.png", bbox_inches="tight")
328
+ plt.close(fig)
329
+
330
+
331
+ def plot_pipeline():
332
+ fig, ax = plt.subplots(figsize=(11.4, 5.2), dpi=220)
333
+ ax.set_xlim(0, 10); ax.set_ylim(0, 7); ax.axis("off")
334
+ boxes = [
335
+ (0.5, 5.3, "Capture +\ncalibration", "K, distortion, RMS"),
336
+ (3.6, 5.3, "ORB +\nmatching", "keypoints, inliers"),
337
+ (6.7, 5.3, "Pose +\ntriangulation", "poses, reprojection"),
338
+ (0.5, 2.3, "Quality +\nprofiling", "error, runtime, failure"),
339
+ (3.6, 2.3, "Dense/mesh\nhandoff", "geometry, texture, LOD"),
340
+ (6.7, 2.3, "Semantic asset\npackage", "glTF, provenance, ontology"),
341
+ ]
342
+ colors = ["#dceaf7", "#e4f0dc", "#fff0cb", "#f8dfdc", "#eee2f5", "#d9efed"]
343
+ for (x, y, title, output), col in zip(boxes, colors):
344
+ rect = plt.Rectangle((x, y), 2.45, 1.15, facecolor=col, edgecolor="#35516a", linewidth=1.2)
345
+ ax.add_patch(rect)
346
+ ax.text(x+1.225, y+0.72, title, ha="center", va="center", fontsize=10, weight="bold")
347
+ ax.text(x+1.225, y+0.22, output, ha="center", va="center", fontsize=7.7, color="#36454f")
348
+ arrows = [((2.95, 5.88), (3.55, 5.88)), ((6.05, 5.88), (6.65, 5.88)),
349
+ ((7.92, 5.28), (1.73, 3.47)), ((2.95, 2.88), (3.55, 2.88)),
350
+ ((6.05, 2.88), (6.65, 2.88))]
351
+ for a, b in arrows:
352
+ ax.annotate("", xy=b, xytext=a, arrowprops=dict(arrowstyle="->", lw=1.5, color="#35516a"))
353
+ ax.text(5, 6.75, "Inspectable reconstruction and metaverse-content learning workflow",
354
+ ha="center", va="center", fontsize=13, weight="bold", color="#24445c")
355
+ ax.text(5, 1.25, "Assessment checkpoints: explain → implement → measure → diagnose → package",
356
+ ha="center", va="center", fontsize=10, style="italic", color="#475569")
357
+ fig.tight_layout()
358
+ fig.savefig(OUT / "figure4_instructional_pipeline.png", bbox_inches="tight")
359
+ plt.close(fig)
360
+
361
+
362
+ def plot_scene_sequences():
363
+ labels = [
364
+ ("device", "Textured tabletop object"),
365
+ ("facade", "Planar/repeated-pattern facade"),
366
+ ("artifact", "Curved multi-surface artifact"),
367
+ ]
368
+ fig, axes = plt.subplots(3, 1, figsize=(12.0, 5.7), dpi=220)
369
+ for ax, (stem, label) in zip(axes, labels):
370
+ im = cv2.cvtColor(cv2.imread(str(OUT / f"{stem}_views.png")), cv2.COLOR_BGR2RGB)
371
+ ax.imshow(im)
372
+ ax.axis("off")
373
+ ax.text(0.01, 0.92, label, transform=ax.transAxes, fontsize=10, weight="bold",
374
+ color="#17324d", bbox=dict(facecolor="white", edgecolor="none", alpha=0.82, pad=2))
375
+ fig.suptitle("Controlled scene diversity and representative viewpoints", fontsize=13,
376
+ weight="bold", color="#24445c", y=0.995)
377
+ fig.tight_layout(pad=0.7)
378
+ fig.savefig(OUT / "figure2_scene_sequences.png", bbox_inches="tight")
379
+ plt.close(fig)
380
+
381
+
382
+ def plot_accuracy_diagnostics(results: list[dict]):
383
+ labels = {
384
+ "device": "Textured object",
385
+ "facade": "Repeated facade",
386
+ "artifact": "Curved artifact",
387
+ }
388
+ colors = {"device": "#2f6f9f", "facade": "#d47a21", "artifact": "#3d8b5a"}
389
+ markers = {"device": "o", "facade": "s", "artifact": "^"}
390
+ fig = plt.figure(figsize=(9.2, 6.0), dpi=220, facecolor="white")
391
+ grid = fig.add_gridspec(2, 2, height_ratios=[1, 1.05], hspace=0.48, wspace=0.32)
392
+ ax_rot = fig.add_subplot(grid[0, 0])
393
+ ax_trans = fig.add_subplot(grid[0, 1])
394
+ ax_surface = fig.add_subplot(grid[1, :])
395
+ for scene in labels:
396
+ rows = sorted((row for row in results if row["scene"] == scene), key=lambda row: row["views"])
397
+ x = [row["views"] for row in rows]
398
+ common = dict(
399
+ color=colors[scene], marker=markers[scene], linewidth=2.0,
400
+ markersize=6.2, label=labels[scene],
401
+ )
402
+ ax_rot.plot(x, [row["rotation_error_deg"] for row in rows], **common)
403
+ ax_trans.plot(x, [row["translation_error_deg"] for row in rows], **common)
404
+ ax_surface.plot(x, [100 * row["precision_delta_0_12"] for row in rows], **common)
405
+ for ax, title, ylabel in [
406
+ (ax_rot, "(a) Median adjacent-pair rotation error", "Error (degrees)"),
407
+ (ax_trans, "(b) Median translation-direction error", "Error (degrees)"),
408
+ (ax_surface, "(c) Surface-consistent reconstructed points", "Within δ = 0.12 (%)"),
409
+ ]:
410
+ ax.set_title(title, fontsize=10.2, weight="bold", color="#24445c")
411
+ ax.set_xlabel("Views on the fixed 68° arc", fontsize=8.8)
412
+ ax.set_ylabel(ylabel, fontsize=8.8)
413
+ ax.set_xticks([12, 24, 48])
414
+ ax.grid(True, alpha=0.28, linewidth=0.7)
415
+ ax.tick_params(labelsize=8.2)
416
+ ax_rot.set_ylim(bottom=0)
417
+ ax_trans.set_ylim(0, 190)
418
+ ax_surface.set_ylim(0, 25)
419
+ handles, legend_labels = ax_surface.get_legend_handles_labels()
420
+ fig.legend(handles, legend_labels, loc="lower center", ncol=3, frameon=False,
421
+ fontsize=9.0, bbox_to_anchor=(0.5, 0.005))
422
+ fig.suptitle("Ground-truth accuracy diagnostics for the controlled benchmark",
423
+ fontsize=12.5, weight="bold", color="#17324d", y=0.985)
424
+ fig.subplots_adjust(bottom=0.14, top=0.90)
425
+ fig.savefig(OUT / "figure3_accuracy_diagnostics.png", bbox_inches="tight")
426
+ plt.close(fig)
427
+
428
+
429
+ def main():
430
+ scenes = ["device", "facade", "artifact"]
431
+ view_counts = [12, 24, 48]
432
+ results = []
433
+ selected = None
434
+ selected_pose = None
435
+ for scene in scenes:
436
+ for n in view_counts:
437
+ angles = np.linspace(-34, 34, n)
438
+ images, poses = [], []
439
+ for idx, a in enumerate(angles):
440
+ im, pose = render(scene, float(a), idx)
441
+ images.append(im); poses.append(pose)
442
+ if n == 12:
443
+ contact = cv2.hconcat([cv2.resize(images[i], (320, 180)) for i in [0, 3, 6, 9]])
444
+ cv2.imwrite(str(OUT / f"{scene}_views.png"), contact)
445
+ res = reconstruct(images, poses)
446
+ prec, med = geometric_precision(scene, res["points"], *poses[0])
447
+ row = {k: v for k, v in res.items() if k not in ("points", "colors")}
448
+ row.update({"scene": scene, "views": n, "points": int(len(res["points"])),
449
+ "precision_delta_0_12": prec, "median_surface_distance": med})
450
+ results.append(row)
451
+ print(json.dumps(row, default=float))
452
+ if scene == "artifact" and n == 24:
453
+ selected = res; selected_pose = poses[0]
454
+ with (OUT / "benchmark_results.json").open("w", encoding="utf-8") as f:
455
+ json.dump(results, f, indent=2)
456
+ if selected is not None:
457
+ np.savez_compressed(
458
+ OUT / "artifact24_points.npz",
459
+ points=selected["points"],
460
+ colors=selected["colors"],
461
+ )
462
+ plot_comparison(ROOT / "media" / "image2.jpg", selected, "artifact", *selected_pose)
463
+ plot_scene_sequences()
464
+ plot_accuracy_diagnostics(results)
465
+ # Figure 4 is supplied separately as an editable C4 SVG and publication PNG.
466
+
467
+
468
+ if __name__ == "__main__":
469
+ main()
media/image2.jpg ADDED

Git LFS Details

  • SHA256: c2c604026051ba5e6939e6d25771920207e16c30b074721254791f215e1b99b1
  • Pointer size: 130 Bytes
  • Size of remote file: 12.8 kB
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ matplotlib==3.10.8
2
+ numpy==2.5.1
3
+ opencv-python-headless==4.11.0.86
4
+ Pillow==12.2.0
5
+ scipy==1.17.0