本文整理匯總了Python中plyfile.PlyData.read方法的典型用法代碼示例。如果您正苦於以下問題:Python PlyData.read方法的具體用法?Python PlyData.read怎麽用?Python PlyData.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類plyfile.PlyData
的用法示例。
在下文中一共展示了PlyData.read方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: read_tsdf
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def read_tsdf(filename):
f = open(filename, 'rb')
fileContent = f.read()
A = struct.unpack("<3f", fileContent[:12])
A = np.array(A, np.int32)
# print(A)
s1 = A[2]
s2 = A[0]
s3 = A[1]
size = int(A[0]*A[1]*A[2])
s = "<%df"%(int(size))
TDF = struct.unpack(s, fileContent[12:12+size*4])
out = np.zeros((s1, s2, s3))
for i in range(s1):
t = np.transpose(np.reshape(TDF[i*s2*s3: (i+1)*s2*s3], (s3, s2)))
out[i] = t
out = np.transpose(out, (1,2,0))
out = out[20:-20, 20:-20, 20:-20]
return out
示例2: read_ply_xyzrgbnormal
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def read_ply_xyzrgbnormal(filename):
""" read XYZ RGB normals point cloud from filename PLY file """
assert(os.path.isfile(filename))
with open(filename, 'rb') as f:
plydata = PlyData.read(f)
num_verts = plydata['vertex'].count
vertices = np.zeros(shape=[num_verts, 9], dtype=np.float32)
vertices[:,0] = plydata['vertex'].data['x']
vertices[:,1] = plydata['vertex'].data['y']
vertices[:,2] = plydata['vertex'].data['z']
vertices[:,3] = plydata['vertex'].data['red']
vertices[:,4] = plydata['vertex'].data['green']
vertices[:,5] = plydata['vertex'].data['blue']
# compute normals
xyz = np.array([[x, y, z] for x, y, z, _, _, _, _ in plydata["vertex"].data])
face = np.array([f[0] for f in plydata["face"].data])
nxnynz = compute_normal(xyz, face)
vertices[:,6:] = nxnynz
return vertices
示例3: load_ply_mesh
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def load_ply_mesh(mesh_path):
data = PlyData.read(mesh_path)
vertex_data = data['vertex'].data
vertices = np.zeros([vertex_data.shape[0], 3], dtype=np.float32)
for i in range(vertices.shape[0]):
for j in range(3):
vertices[i, j] = vertex_data[i][j]
face_data = data['face'].data
faces = np.zeros([face_data.shape[0], 3], dtype=np.int32)
for i in range(faces.shape[0]):
for j in range(3):
faces[i, j] = face_data[i][0][j]
return vertices, faces
示例4: read_mesh_vertices_rgb
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def read_mesh_vertices_rgb(filename):
""" read XYZ RGB for each vertex.
Note: RGB values are in 0-255
"""
assert os.path.isfile(filename)
with open(filename, 'rb') as f:
plydata = PlyData.read(f)
num_verts = plydata['vertex'].count
vertices = np.zeros(shape=[num_verts, 6], dtype=np.float32)
vertices[:,0] = plydata['vertex'].data['x']
vertices[:,1] = plydata['vertex'].data['y']
vertices[:,2] = plydata['vertex'].data['z']
vertices[:,3] = plydata['vertex'].data['red']
vertices[:,4] = plydata['vertex'].data['green']
vertices[:,5] = plydata['vertex'].data['blue']
return vertices
示例5: load_mesh
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def load_mesh(mesh_file):
with open(mesh_file, 'r') as f:
str_file = f.read().split('\n')
n_vertices, n_faces, _ = list(
map(lambda x: int(x), str_file[1].split(' ')))
str_file = str_file[2:] # Remove first 2 lines
v = [l.split(' ') for l in str_file[:n_vertices]]
f = [l.split(' ') for l in str_file[n_vertices:]]
v = np.array(v).astype(np.float32)
f = np.array(f).astype(np.uint64)[:, 1:4]
mesh = trimesh.Trimesh(vertices=v, faces=f, process=False)
return mesh
示例6: load_file
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def load_file(file_name, voxel_size):
plydata = PlyData.read(file_name)
data = plydata.elements[0].data
coords = np.array([data['x'], data['y'], data['z']], dtype=np.float32).T
colors = np.array([data['red'], data['green'], data['blue']], dtype=np.float32).T / 255
labels = np.array(data['label'], dtype=np.int32)
# Generate input pointcloud
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(coords)
pcd.colors = o3d.utility.Vector3dVector(colors)
# Normalize feature
norm_coords = coords - coords.mean(0)
feats = np.concatenate((colors - 0.5, norm_coords), 1)
coords, feats, labels = ME.utils.sparse_quantize(
coords, feats, labels, quantization_size=voxel_size)
return coords, feats, labels, pcd
示例7: load_ply_file
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def load_ply_file(fname) :
"""Loads a .ply mesh to return a collection of weighted Dirac atoms: one per triangle face."""
# Load the data, and read the connectivity information:
plydata = PlyData.read(fname)
triangles = np.vstack( plydata['face'].data['vertex_indices'] )
# Normalize the point cloud, as specified by the user:
points = np.vstack( [ [v[0],v[1],v[2]] for v in plydata['vertex'] ] )
return to_measure(points, triangles)
################################################################################
# Utility: load ".nii" volume file.
#
示例8: __getitem__
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def __getitem__(self, index):
fn = self.fns[index]
cls = self.cat[fn.split('/')[0]]
with open(os.path.join(self.root, fn), 'rb') as f:
plydata = PlyData.read(f)
pts = np.vstack([plydata['vertex']['x'], plydata['vertex']['y'], plydata['vertex']['z']]).T
choice = np.random.choice(len(pts), self.npoints, replace=True)
point_set = pts[choice, :]
point_set = point_set - np.expand_dims(np.mean(point_set, axis=0), 0) # center
dist = np.max(np.sqrt(np.sum(point_set ** 2, axis=1)), 0)
point_set = point_set / dist # scale
if self.data_augmentation:
theta = np.random.uniform(0, np.pi * 2)
rotation_matrix = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]])
point_set[:, [0, 2]] = point_set[:, [0, 2]].dot(rotation_matrix) # random rotation
point_set += np.random.normal(0, 0.02, size=point_set.shape) # random jitter
point_set = torch.from_numpy(point_set.astype(np.float32))
cls = torch.from_numpy(np.array([cls]).astype(np.int64))
return point_set, cls
示例9: readPlyFile
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def readPlyFile(filename):
"""
Usese plyfile python pacakage to read a ply file.
Gets around issues with pcl having a bad ply writer for pointclouds
:param filename:
:type filename: str
:return: vtkPolyData
:rtype:
"""
from plyfile import PlyData
plydata = PlyData.read(filename)
vertex_data = plydata['vertex'].data # numpy array with fields ['x', 'y', 'z']
pts = np.zeros([vertex_data.size, 3])
pts[:, 0] = vertex_data['x']
pts[:, 1] = vertex_data['y']
pts[:, 2] = vertex_data['z']
return vnp.numpyToPolyData(pts)
示例10: dataSource
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def dataSource(fn):
with open(fn, 'rb') as f:
plydata=PlyData.read(f)
#print(plydata,'\n',plydata['vertex'][0],'\n',plydata.elements[0].properties)
print(plydata) #可以通過打印,查看讀取的點雲數據格式,從而進一步提取所需數據。
pointsX=plydata['vertex']['x'] #等同於plydata['vertex'][0]
pointsY=plydata['vertex']['y']
pointsZ=plydata['vertex']['z']
pointsR=plydata['vertex']['red']
pointsG=plydata['vertex']['green']
pointsB=plydata['vertex']['blue']
pointsXYZ=np.array([pointsX,pointsY,pointsZ])
pointsRGB=np.array([pointsR,pointsG,pointsB])
#[:,:1000]
print(pointsRGB.shape,pointsXYZ.shape)
print(pointsRGB.transpose())
return pointsXYZ,pointsRGB
示例11: read_ply
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def read_ply(filename):
""" read XYZ point cloud from filename PLY file """
plydata = PlyData.read(filename)
pc = plydata['vertex'].data
pc_array = np.array([[x, y, z] for x,y,z in pc])
return pc_array
示例12: get_xyz_max
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def get_xyz_max(fn_read):
plydata = PlyData.read(fn_read)
#x,y,z : embbedding to RGB
x_ct = np.mean(plydata.elements[0].data['x'])
x_abs = np.max(np.abs(plydata.elements[0].data['x']-x_ct))
y_ct = np.mean(plydata.elements[0].data['y'])
y_abs = np.max(np.abs(plydata.elements[0].data['y']-y_ct))
z_ct = np.mean(plydata.elements[0].data['z'])
z_abs = np.max(np.abs(plydata.elements[0].data['z']-z_ct))
return x_abs,y_abs,z_abs,x_ct,y_ct,z_ct
示例13: convert_unique
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def convert_unique(fn_read,fn_write,center_x=True,center_y=True,center_z=True):
plydata = PlyData.read(fn_read)
#x,y,z : embbedding to RGB
x_ct = np.mean(plydata.elements[0].data['x'])
if not(center_x):
x_ct=0
x_abs = np.max(np.abs(plydata.elements[0].data['x']-x_ct))
y_ct = np.mean(plydata.elements[0].data['y'])
if not(center_y):
y_ct=0
y_abs = np.max(np.abs(plydata.elements[0].data['y']-y_ct))
z_ct = np.mean(plydata.elements[0].data['z'])
if not(center_z):
z_ct=0
z_abs = np.max(np.abs(plydata.elements[0].data['z']-z_ct))
n_vert = plydata.elements[0].data['x'].shape[0]
for i in range(n_vert):
r=(plydata.elements[0].data['x'][i]-x_ct)/x_abs #-1 to 1
r = (r+1)/2 #0 to 2 -> 0 to 1
g=(plydata.elements[0].data['y'][i]-y_ct)/y_abs
g = (g+1)/2
b=(plydata.elements[0].data['z'][i]-z_ct)/z_abs
b = (b+1)/2
#if b> 1: b=1
#if b<0: b=0
plydata.elements[0].data['red'][i]=r*255
plydata.elements[0].data['green'][i]=g*255
plydata.elements[0].data['blue'][i]=b*255
plydata.write(fn_write)
return x_abs,y_abs,z_abs,x_ct,y_ct,z_ct
示例14: read_ply_xyz
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def read_ply_xyz(filename):
""" read XYZ point cloud from filename PLY file """
assert(os.path.isfile(filename))
with open(filename, 'rb') as f:
plydata = PlyData.read(f)
num_verts = plydata['vertex'].count
vertices = np.zeros(shape=[num_verts, 3], dtype=np.float32)
vertices[:,0] = plydata['vertex'].data['x']
vertices[:,1] = plydata['vertex'].data['y']
vertices[:,2] = plydata['vertex'].data['z']
return vertices
示例15: read_ply_xyzrgb
# 需要導入模塊: from plyfile import PlyData [as 別名]
# 或者: from plyfile.PlyData import read [as 別名]
def read_ply_xyzrgb(filename):
""" read XYZRGB point cloud from filename PLY file """
assert(os.path.isfile(filename))
with open(filename, 'rb') as f:
plydata = PlyData.read(f)
num_verts = plydata['vertex'].count
vertices = np.zeros(shape=[num_verts, 6], dtype=np.float32)
vertices[:,0] = plydata['vertex'].data['x']
vertices[:,1] = plydata['vertex'].data['y']
vertices[:,2] = plydata['vertex'].data['z']
vertices[:,3] = plydata['vertex'].data['red']
vertices[:,4] = plydata['vertex'].data['green']
vertices[:,5] = plydata['vertex'].data['blue']
return vertices