本文整理匯總了Python中plyfile.PlyData方法的典型用法代碼示例。如果您正苦於以下問題:Python plyfile.PlyData方法的具體用法?Python plyfile.PlyData怎麽用?Python plyfile.PlyData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類plyfile
的用法示例。
在下文中一共展示了plyfile.PlyData方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: write
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def write(self, path):
"""
Writes the object to file. This is a wrapper for :func:`plyfile.PlyData.write`
:param path: The path of the ouput file.
"""
if len(self.points) > 0:
# coordinate_array = self.points[["x", "y", "z"]].values.T
# vertex_array = list(zip(coordinate_array[0],coordinate_array[1], coordinate_array[2]))
# vertex_array = np.array(vertex_array, dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
vertex_array = self.points.to_records(index=False)
elements = plyfile.PlyElement.describe(vertex_array, "vertex")
plyfile.PlyData([elements]).write(path)
else:
raise ValueError(
"There is no data contained in this Cloud object, it is impossible to write."
)
示例2: visualize
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def visualize(args):
print("visualizing...")
scene = np.load(CONF.SCANNETV2_FILE.format(args.scene_id))
vertex = []
for i in range(scene.shape[0]):
vertex.append(
(
scene[i][0],
scene[i][1],
scene[i][2],
CONF.PALETTE[int(scene[i][7])][0],
CONF.PALETTE[int(scene[i][7])][1],
CONF.PALETTE[int(scene[i][7])][2]
)
)
vertex = np.array(
vertex,
dtype=[
("x", np.dtype("float32")),
("y", np.dtype("float32")),
("z", np.dtype("float32")),
("red", np.dtype("uint8")),
("green", np.dtype("uint8")),
("blue", np.dtype("uint8"))
]
)
output_pc = PlyElement.describe(vertex, "vertex")
output_pc = PlyData([output_pc])
os.makedirs(CONF.SCAN_LABELS, exist_ok=True)
output_pc.write(CONF.SCANNETV2_LABEL.format(args.scene_id))
示例3: visualize
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def visualize(args, preds):
vertex = []
for i in range(preds.shape[0]):
vertex.append(
(
preds[i][0],
preds[i][1],
preds[i][2],
preds[i][3],
preds[i][4],
preds[i][5],
)
)
vertex = np.array(
vertex,
dtype=[
("x", np.dtype("float32")),
("y", np.dtype("float32")),
("z", np.dtype("float32")),
("red", np.dtype("uint8")),
("green", np.dtype("uint8")),
("blue", np.dtype("uint8"))
]
)
output_pc = PlyElement.describe(vertex, "vertex")
output_pc = PlyData([output_pc])
output_root = os.path.join(CONF.OUTPUT_ROOT, args.folder, "preds")
os.makedirs(output_root, exist_ok=True)
output_pc.write(os.path.join(output_root, "{}.ply".format(args.scene_id)))
示例4: save_ply
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def save_ply(points, filename, colors=None, normals=None):
vertex = np.core.records.fromarrays(points.transpose(), names='x, y, z', formats='f4, f4, f4')
n = len(vertex)
desc = vertex.dtype.descr
if normals is not None:
vertex_normal = np.core.records.fromarrays(normals.transpose(), names='nx, ny, nz', formats='f4, f4, f4')
assert len(vertex_normal) == n
desc = desc + vertex_normal.dtype.descr
if colors is not None:
vertex_color = np.core.records.fromarrays(colors.transpose() * 255, names='red, green, blue',
formats='u1, u1, u1')
assert len(vertex_color) == n
desc = desc + vertex_color.dtype.descr
vertex_all = np.empty(n, dtype=desc)
for prop in vertex.dtype.names:
vertex_all[prop] = vertex[prop]
if normals is not None:
for prop in vertex_normal.dtype.names:
vertex_all[prop] = vertex_normal[prop]
if colors is not None:
for prop in vertex_color.dtype.names:
vertex_all[prop] = vertex_color[prop]
ply = plyfile.PlyData([plyfile.PlyElement.describe(vertex_all, 'vertex')], text=False)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
ply.write(filename)
示例5: save_ply
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def save_ply(points, filename, colors=None, normals=None):
vertex = np.core.records.fromarrays(points.transpose(), names='x, y, z', formats='f4, f4, f4')
n = len(vertex)
desc = vertex.dtype.descr
if normals is not None:
vertex_normal = np.core.records.fromarrays(normals.transpose(), names='nx, ny, nz', formats='f4, f4, f4')
assert len(vertex_normal) == n
desc = desc + vertex_normal.dtype.descr
if colors is not None:
vertex_color = np.core.records.fromarrays(colors.transpose() * 255, names='red, green, blue',
formats='u1, u1, u1')
assert len(vertex_color) == n
desc = desc + vertex_color.dtype.descr
vertex_all = np.empty(n, dtype=desc)
for prop in vertex.dtype.names:
vertex_all[prop] = vertex[prop]
if normals is not None:
for prop in vertex_normal.dtype.names:
vertex_all[prop] = vertex_normal[prop]
if colors is not None:
for prop in vertex_color.dtype.names:
vertex_all[prop] = vertex_color[prop]
ply = plyfile.PlyData([plyfile.PlyElement.describe(vertex_all, 'vertex')], text=False)
#if not os.path.exists(os.path.dirname(filename)):
# os.makedirs(os.path.dirname(filename))
ply.write(filename)
示例6: save_ply
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def save_ply(points, filename, colors=None, normals=None):
vertex = np.array([tuple(p) for p in points], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
n = len(vertex)
desc = vertex.dtype.descr
if normals is not None:
vertex_normal = np.array([tuple(n) for n in normals], dtype=[('nx', 'f4'), ('ny', 'f4'), ('nz', 'f4')])
assert len(vertex_normal) == n
desc = desc + vertex_normal.dtype.descr
if colors is not None:
vertex_color = np.array([tuple(c * 255) for c in colors],
dtype=[('red', 'u1'), ('green', 'u1'), ('blue', 'u1')])
assert len(vertex_color) == n
desc = desc + vertex_color.dtype.descr
vertex_all = np.empty(n, dtype=desc)
for prop in vertex.dtype.names:
vertex_all[prop] = vertex[prop]
if normals is not None:
for prop in vertex_normal.dtype.names:
vertex_all[prop] = vertex_normal[prop]
if colors is not None:
for prop in vertex_color.dtype.names:
vertex_all[prop] = vertex_color[prop]
ply = plyfile.PlyData([plyfile.PlyElement.describe(vertex_all, 'vertex')], text=False)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
ply.write(filename)
示例7: read_3d_point_cloud_from_ply
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def read_3d_point_cloud_from_ply(path_to_ply_file):
"""
Read a 3D point cloud from a ply file and return a numpy array.
Args:
path_to_ply_file (str): path to a .ply file
Returns:
numpy array with the list of 3D points, one point per line
list of strings with the ply header comments
"""
plydata = plyfile.PlyData.read(path_to_ply_file)
d = np.asarray(plydata['vertex'].data)
array = np.column_stack([d[p.name] for p in plydata['vertex'].properties])
return array, plydata.comments
示例8: write_3d_point_cloud_to_ply
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def write_3d_point_cloud_to_ply(path_to_ply_file, coordinates, colors=None,
extra_properties=None,
extra_properties_names=None, comments=[]):
"""
Write a 3D point cloud to a ply file.
Args:
path_to_ply_file (str): path to a .ply file
coordinates (array): numpy array of shape (n, 3) containing x, y, z coordinates
colors (array): numpy array of shape (n, 3) or (n, 1) containing either
r, g, b or gray levels
extra_properties (array): optional numpy array of shape (n, k)
extra_properties_names (list): list of k strings with the names of the
(optional) extra properties
comments (list): list of strings containing the ply header comments
"""
points = coordinates
dtypes = [('x', coordinates.dtype),
('y', coordinates.dtype),
('z', coordinates.dtype)]
if colors is not None:
if colors.shape[1] == 1: # replicate grayscale 3 times
colors = np.column_stack([colors] * 3)
elif colors.shape[1] != 3:
raise Exception('Error: colors must have either 1 or 3 columns')
points = np.column_stack((points, colors))
dtypes += [('red', colors.dtype),
('green', colors.dtype),
('blue', colors.dtype)]
if extra_properties is not None:
points = np.column_stack((points, extra_properties))
dtypes += [(s, extra_properties.dtype) for s in extra_properties_names]
tuples = [tuple(x) for x in points]
plydata = plyfile.PlyElement.describe(np.asarray(tuples, dtype=dtypes),
'vertex')
plyfile.PlyData([plydata], comments=comments).write(path_to_ply_file)
示例9: write_ply_to_file
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def write_ply_to_file(path, position, orientation, acceleration=None,
global_rotation=np.identity(3, float), local_axis=None,
trajectory_color=None, num_axis=3,
length=1.0, kpoints=100, interval=100):
"""
Visualize camera trajectory as ply file
:param path: path to save
:param position: Nx3 array of positions
:param orientation: Nx4 array or orientation as quaternion
:param acceleration: (optional) Nx3 array of acceleration
:param global_rotation: (optional) global rotation
:param local_axis: (optional) local axis vector
:param trajectory_color: (optional) the color of the trajectory. The default is [255, 0, 0] (red)
:return: None
"""
num_cams = position.shape[0]
assert orientation.shape[0] == num_cams
max_acceleration = 1.0
if acceleration is not None:
assert acceleration.shape[0] == num_cams
max_acceleration = max(np.linalg.norm(acceleration, axis=1))
print('max_acceleration: ', max_acceleration)
num_axis = 4
sample_pt = np.arange(0, num_cams, interval, dtype=int)
num_sample = sample_pt.shape[0]
# Define the optional transformation. Default is set w.r.t tango coordinate system
position_transformed = np.matmul(global_rotation, np.array(position).transpose()).transpose()
if local_axis is None:
local_axis = np.array([[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0]])
if trajectory_color is None:
trajectory_color = [0, 255, 255]
axis_color = [[255, 0, 0], [0, 255, 0], [0, 0, 255], [255, 0, 255]]
vertex_type = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('red', 'u1'), ('green', 'u1'), ('blue', 'u1')]
positions_data = np.empty((position_transformed.shape[0],), dtype=vertex_type)
positions_data[:] = [tuple([*i, *trajectory_color]) for i in position_transformed]
app_vertex = np.empty([num_axis * kpoints], dtype=vertex_type)
for i in range(num_sample):
q = quaternion.quaternion(*orientation[sample_pt[i]])
if acceleration is not None:
local_axis[:, -1] = acceleration[sample_pt[i]].flatten() / max_acceleration
global_axes = np.matmul(global_rotation, np.matmul(quaternion.as_rotation_matrix(q), local_axis))
for k in range(num_axis):
for j in range(kpoints):
axes_pts = position_transformed[sample_pt[i]].flatten() +\
global_axes[:, k].flatten() * j * length / kpoints
app_vertex[k*kpoints + j] = tuple([*axes_pts, *axis_color[k]])
positions_data = np.concatenate([positions_data, app_vertex], axis=0)
vertex_element = plyfile.PlyElement.describe(positions_data, 'vertex')
plyfile.PlyData([vertex_element], text=True).write(path)
示例10: __init__
# 需要導入模塊: import plyfile [as 別名]
# 或者: from plyfile import PlyData [as 別名]
def __init__(self, path):
if type(path) == str or type(path) == pathlib.PosixPath:
self.filepath = path
self.name = os.path.splitext(os.path.split(path)[1])[0]
self.extension = os.path.splitext(path)[1]
# A path to las or laz file
if self.extension.lower() == ".las" or self.extension.lower() == ".laz":
las = laspy.file.File(self.filepath)
self._get_las_points(las)
elif self.extension.lower() == ".ply":
ply = plyfile.PlyData.read(path)
ply_points = ply.elements[0].data
points = pd.DataFrame(
{"x": ply_points["x"], "y": ply_points["y"], "z": ply_points["z"]}
)
header = "ply_header"
self.data = PLYData(points, header)
else:
raise ValueError(
"File extension not supported, please input either a las, laz, ply or CloudData object."
)
elif type(path) == CloudData or isinstance(path, CloudData):
self.data = path
if type(self.data.header) == laspy.header.HeaderManager:
self.data = LASData(self.data.points, self.data.header)
elif self.data.header == "ply_header":
self.data = PLYData(self.data.points, self.data.header)
elif (
path.__class__.__bases__[0] == laspy.file.File
or type(path) == laspy.file.File
):
self._get_las_points(path)
else:
raise ValueError(
"Object type not supported, please input either a file path with a supported extension or a CloudData object."
)
# We're not sure if this is true or false yet
self.normalized = None
self.crs = None