Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_octree_convert_from_point_cloud():
octree = o3d.geometry.Octree(1, [0, 0, 0], 2)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(_eight_cubes_points)
pcd.colors = o3d.utility.Vector3dVector(_eight_cubes_colors)
octree.convert_from_point_cloud(pcd)
def write_color_distances(path, pcd, distances, max_distance):
o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug)
# cmap = plt.get_cmap("afmhot")
cmap = plt.get_cmap("hot_r")
distances = np.array(distances)
colors = cmap(np.minimum(distances, max_distance) / max_distance)[:, :3]
pcd.colors = o3d.utility.Vector3dVector(colors)
o3d.io.write_point_cloud(path, pcd)
tri_id = self.pixel_tris[v,u]
if tri_id != -1:
pixel = self.pixel[v,u]
norm_tri = datas[tri_id,0:3]
h_tri = datas[tri_id,3]
depth = h_tri/(norm_tri[0]*pixel[0]+norm_tri[1]*pixel[1]+norm_tri[2])
if(depth)<0:
print('there should be an error',depth,pixel,datas[tri_id])
depth_img[v,u] =depth
point = [pixel[0]*depth,pixel[1]*depth,depth]
point_clouds.append(point)
colors.append(img[v,u,::-1]/255.0)
depth_img = depth_img/np.max(depth_img)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(np.array(point_clouds))
pcd.colors = o3d.utility.Vector3dVector(np.array(colors))
o3d.io.write_point_cloud("pointcloud.ply", pcd)
cv2.imshow('img_depth',depth_img/np.max(depth_img))
print(np.min(depth_img),np.max(depth_img),np.mean(depth_img))
def plane(height=0.2, width=1):
mesh = o3d.geometry.TriangleMesh(
vertices=o3d.utility.Vector3dVector(
np.array(
[[0, 0, 0], [0, height, 0], [width, height, 0], [width, 0, 0]],
dtype=np.float32,
)),
triangles=o3d.utility.Vector3iVector(np.array([[0, 2, 1], [2, 0, 3]])),
)
mesh.compute_vertex_normals()
return mesh
junction_set.points = open3d.utility.Vector3dVector(connected_junctions)
junction_set.colors = open3d.utility.Vector3dVector(connected_colors)
# visualize line segments
line_colors = np.repeat(colormap[5].reshape(1, 3), len(junction_pairs), axis=0)
# color holes
if len(lines_holes) != 0:
line_colors[lines_holes] = colormap[6]
# color cuboids
if len(cuboid_lines) != 0:
line_colors[cuboid_lines] = colormap[2]
line_set = open3d.geometry.LineSet()
line_set.points = open3d.utility.Vector3dVector(junctions)
line_set.lines = open3d.utility.Vector2iVector(junction_pairs)
line_set.colors = open3d.utility.Vector3dVector(line_colors)
open3d.visualization.draw_geometries([junction_set, line_set])
# generate some neat n times 3 matrix using a variant of sync function
x = np.linspace(-3, 3, 401)
mesh_x, mesh_y = np.meshgrid(x, x)
z = np.sinc((np.power(mesh_x, 2) + np.power(mesh_y, 2)))
z_norm = (z - z.min()) / (z.max() - z.min())
xyz = np.zeros((np.size(mesh_x), 3))
xyz[:, 0] = np.reshape(mesh_x, -1)
xyz[:, 1] = np.reshape(mesh_y, -1)
xyz[:, 2] = np.reshape(z_norm, -1)
print('xyz')
print(xyz)
# Pass xyz to Open3D.o3d.geometry.PointCloud and visualize
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(xyz)
o3d.io.write_point_cloud("../../TestData/sync.ply", pcd)
# Load saved point cloud and visualize it
pcd_load = o3d.io.read_point_cloud("../../TestData/sync.ply")
o3d.visualization.draw_geometries([pcd_load])
# convert Open3D.o3d.geometry.PointCloud to numpy array
xyz_load = np.asarray(pcd_load.points)
print('xyz_load')
print(xyz_load)
# save z_norm as an image (change [0,1] range to [0,255] range with uint8 type)
img = o3d.geometry.Image((z_norm * 255).astype(np.uint8))
o3d.io.write_image("../../TestData/sync.png", img)
o3d.visualization.draw_geometries([img])
def fit_step_callback(vis):
fps.step() # Get ONE new sample
pcd_selected.points = o3d.utility.Vector3dVector(fps.get_selected_pts())
pcd_selected.paint_uniform_color([1, 0, 0]) # selected: red
vis.update_geometry()
def display_mesh(self, width=640, height=360):
self.mesh.points = o3d.utility.Vector3dVector(self.pointcloud)
o3d.visualization.draw_geometries(self.objs, width=width, height=height)
[2, 3],
[4, 5],
[4, 6],
[5, 7],
[6, 7],
[0, 4],
[1, 5],
[2, 6],
[3, 7],
]
colors = [[1, 0, 0] for i in range(len(lines))]
line_set = o3d.geometry.LineSet(
points=o3d.utility.Vector3dVector(points),
lines=o3d.utility.Vector2iVector(lines),
)
line_set.colors = o3d.utility.Vector3dVector(colors)
o3d.visualization.draw_geometries([line_set])
print("Let's draw a textured triangle mesh from obj file.")
textured_mesh = o3d.io.read_triangle_mesh("../../TestData/crate/crate.obj")
textured_mesh.compute_vertex_normals()
o3d.visualization.draw_geometries([textured_mesh])