本文介绍了Open3D中open3d.geometry.AxisAlignedBoundingBox的color参数的使用。
color
参数为网格边框的颜色,可以为Python中的int类型或者float类型的颜色值。它可以让网格边框更具可视性。
color
参数默认为空,即为黑色。如果要设置颜色,可以用以下方式:
int类型:将颜色的RGB值(0~255)拼接成一个整数值,如红色为(255,0,0),则对应的int值为16711680。将该值作为color
的参数值即可。
float类型:将颜色的RGB值(0~1)作为一个三元组,如红色为(1.0,0.0,0.0),则对应的float值为[1.0,0.0,0.0]。将该值作为color
的参数值即可。
以下是两种类型的代码示例:
import open3d as o3d
# 使用int类型的颜色值
int_color = 256 * 256 * 255 + 256 * 0 + 0
box = o3d.geometry.AxisAlignedBoundingBox(min_bound=(-1, -1, -1),
max_bound=(1, 1, 1),
color=int_color)
# 使用float类型的颜色值
float_color = [1.0, 0.0, 0.0]
box = o3d.geometry.AxisAlignedBoundingBox(min_bound=(-1, -1, -1),
max_bound=(1, 1, 1),
color=float_color)
以下是使用不同颜色值的示例。
import open3d as o3d
import numpy as np
# 创建点云
points = np.random.rand(100,3)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(points)
# 创建bounding box,并设置颜色
box1 = o3d.geometry.AxisAlignedBoundingBox(min_bound=(-1, -1, -1),
max_bound=(1, 1, 1),
color=16711680) # 红色
box2 = o3d.geometry.AxisAlignedBoundingBox(min_bound=(0, 0, 0),
max_bound=(2, 2, 2),
color=[0.0, 1.0, 0.0]) # 绿色
# 可视化
o3d.visualization.draw_geometries([pcd, box1, box2])
color
参数只对bounding box的边框生效,不会影响内部填充的颜色。
如果同时设置了color
和line_width
参数,则完整代码要求如下:
box = o3d.geometry.AxisAlignedBoundingBox(min_bound=min_bound,
max_bound=max_bound,
color=color,
line_width=line_width)
其中,min_bound
和max_bound
为bounding box的最小和最大顶点坐标,color
为bounding box的边框颜色,line_width
为bounding box的线宽度。
color
参数也适用于open3d.visualization.render_geometry()
方法的可视化,具体使用方法可自行查询相关文档。
Open3D官方文档:https://www.open3d.org/docs/0.9.0/python_api/open3d.geometry.AxisAlignedBoundingBox.html
Python中颜色值的转换:https://blog.csdn.net/weixin_42051150/article/details/100536080