python-pcl点云可视化(借鉴python随机生成区分度较高的颜色)

参考:

python:随机生成区分度较高的颜色

https://blog.csdn.net/yyliunianyy/article/details/102525437

import pcl
import pcl.pcl_visualization

import datetime
import colorsys
import random
def get_n_hls_colors(num):
    hls_colors = []
    i = 0
    step = 360.0 / num
    while i < 360:
        h = i
        s = 90 + random.random() * 10
        l = 50 + random.random() * 10
        _hlsc = [h / 360.0, l / 100.0, s / 100.0]
        hls_colors.append(_hlsc)
        i += step
    return hls_colors

def ncolors(num):
    rgb_colors = []
    if num < 1:
        return rgb_colors
    hls_colors = get_n_hls_colors(num)
    for hlsc in hls_colors:
        _r, _g, _b = colorsys.hls_to_rgb(hlsc[0], hlsc[1], hlsc[2])
        r, g, b = [int(x * 255.0) for x in (_r, _g, _b)]
        rgb_colors.append([r, g, b])
    return rgb_colors

def vis_draw_point_cloud(geoms, color_num):
    colorbar = ncolors(color_num)
    vis = pcl.pcl_visualization.PCLVisualizering
    vis_create_window = pcl.pcl_visualization.PCLVisualizering()

    title_str = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')

    for index, geom in enumerate(geoms):
        point_color = pcl.pcl_visualization.PointCloudColorHandleringCustom(geom, colorbar[index][0], colorbar[index][1], colorbar[index][2])
        vis.AddPointCloud_ColorHandler(vis_create_window, geom, point_color, id=title_str + '_' +'point_cloud_id{:0>3d}'.format(index), viewport=0)

    while not vis.WasStopped(vis_create_window):
        vis.Spin(vis_create_window)

猜你喜欢

转载自blog.csdn.net/baidu_40840693/article/details/108866083