-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreconstruct_sensor.py
More file actions
78 lines (59 loc) · 1.97 KB
/
reconstruct_sensor.py
File metadata and controls
78 lines (59 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Example: perform mesh reconstruction directly from sensors.
This example uses only one sensor.
"""
import sys
from argparse import ArgumentParser
import pyRecFusionSDK as rf
parser = ArgumentParser()
parser.add_argument(
"license_key",
type=str,
help="RecFusionSDK license key required to export the final mesh",
)
parser.add_argument(
"--output-mesh",
type=str,
default="mesh.ply",
help="Path to the reconstructed mesh (*.ply)",
)
args = parser.parse_args()
print(f"Using RecFusionSDK v{rf.sdk.version()}")
if not rf.sdk.activate(args.license_key):
print("ERROR: Invalid RecFusion license. Export will be disabled")
rf.sdk.init()
sensor_manager = rf.SensorManager()
sensor = sensor_manager.open_any()
if not sensor:
rf.sdk.deinit()
sys.exit("ERROR: no sensor was opened!")
cw, ch, dw, dh = sensor.image_size
print(f"Image color size: {cw}x{ch}, depth size: {dw}x{dh}")
params = rf.ReconstructionParams()
# TODO: add ReconstructionParams::add_from_sensor(int, Sensor) ?? copy_from_sensor? fill_from_sensor?
params.set_image_size(cw, ch, dw, dh)
params.set_intrinsics(sensor.depth_intrinsics)
params.set_color_intrinsics(sensor.color_intrinsics)
params.set_depth_to_color_transformation(sensor.depth_to_color_transformation)
reconstruction = rf.Reconstruction(params)
img_color = rf.ColorImage.allocate_for_sensor(sensor)
img_depth = rf.DepthImage.allocate_for_sensor(sensor)
# int frame = 0
max_frames = 100
for frame in range(max_frames):
if not sensor.read_image(img_depth, img_color):
continue
if not reconstruction.add_frame2(0, img_depth, img_color):
break
print("Processed frame:", frame)
sensor.close()
print("Finished reconstruction")
if not reconstruction.good:
rf.deinit()
sys.exit("Failed to reconstruct a mesh")
mesh = reconstruction.get_mesh()
print("Mesh center: ", mesh.center)
print("Mesh #vertices: ", mesh.vertex_count)
print("Mesh #triangles: ", mesh.triangle_count)
print(mesh.vertices)
rf.sdk.deinit()