forked from stereolabs/zed-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmesh_example.py
139 lines (119 loc) · 4.68 KB
/
mesh_example.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
########################################################################
#
# Copyright (c) 2017, STEREOLABS.
#
# All rights reserved.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
########################################################################
"""
Mesh sample shows mesh information after filtering and applying texture on frames. The mesh and its filter
parameters can be saved.
"""
import sys
import pyzed.sl as sl
def main():
if len(sys.argv) != 2:
print("Please specify path to .svo file.")
exit()
filepath = sys.argv[1]
print("Reading SVO file: {0}".format(filepath))
cam = sl.Camera()
init = sl.InitParameters(svo_input_filename=filepath)
status = cam.open(init)
if status != sl.ERROR_CODE.SUCCESS:
print(repr(status))
exit()
runtime = sl.RuntimeParameters()
spatial = sl.SpatialMappingParameters()
transform = sl.Transform()
tracking = sl.TrackingParameters(transform)
cam.enable_tracking(tracking)
cam.enable_spatial_mapping(spatial)
pymesh = sl.Mesh()
print("Processing...")
for i in range(200):
cam.grab(runtime)
cam.request_mesh_async()
cam.extract_whole_mesh(pymesh)
cam.disable_tracking()
cam.disable_spatial_mapping()
filter_params = sl.MeshFilterParameters()
filter_params.set(sl.MESH_FILTER.MESH_FILTER_HIGH)
print("Filtering params : {0}.".format(pymesh.filter(filter_params)))
apply_texture = pymesh.apply_texture(sl.MESH_TEXTURE_FORMAT.MESH_TEXTURE_RGBA)
print("Applying texture : {0}.".format(apply_texture))
print_mesh_information(pymesh, apply_texture)
save_filter(filter_params)
save_mesh(pymesh)
cam.close()
print("\nFINISH")
def print_mesh_information(pymesh, apply_texture):
while True:
res = input("Do you want to display mesh information? [y/n]: ")
if res == "y":
if apply_texture:
print("Vertices : \n{0} \n".format(pymesh.vertices))
print("Uv : \n{0} \n".format(pymesh.uv))
print("Normals : \n{0} \n".format(pymesh.normals))
print("Triangles : \n{0} \n".format(pymesh.triangles))
break
else:
print("Cannot display information of the sl.")
break
if res == "n":
print("Mesh information will not be displayed.")
break
else:
print("Error, please enter [y/n].")
def save_filter(filter_params):
while True:
res = input("Do you want to save the mesh filter parameters? [y/n]: ")
if res == "y":
params = sl.ERROR_CODE.ERROR_CODE_FAILURE
while params != sl.ERROR_CODE.SUCCESS:
filepath = input("Enter filepath name : ")
params = filter_params.save(filepath)
print("Saving mesh filter parameters: {0}".format(repr(params)))
if params:
break
else:
print("Help : you must enter the filepath + filename without extension.")
break
elif res == "n":
print("Mesh filter parameters will not be saved.")
break
else:
print("Error, please enter [y/n].")
def save_mesh(pymesh):
while True:
res = input("Do you want to save the mesh? [y/n]: ")
if res == "y":
msh = sl.ERROR_CODE.ERROR_CODE_FAILURE
while msh != sl.ERROR_CODE.SUCCESS:
filepath = input("Enter filepath name: ")
msh = pymesh.save(filepath)
print("Saving mesh: {0}".format(repr(msh)))
if msh:
break
else:
print("Help : you must enter the filepath + filename without extension.")
break
elif res == "n":
print("Mesh will not be saved.")
break
else:
print("Error, please enter [y/n].")
if __name__ == "__main__":
main()