对于常用的点云PCD文件,存储颜色信息通常由两种格式:
TYPE1:10727339
TYPE2:1.00512e-038
TYPE1
"""
36 46 58
"""
n = 2371130
def rgb_to_number(r,g,b):
return (r*256+g)*256+b
def number_to_rgb(number: int):
num = str(hex(number))
r = int(num[2:4], 16)
g = int(num[4:6], 16)
b = int(num[6:8], 16)
return [r, g, b]
print(number_to_rgb(n))
TYPE2
rgb = 1.00512e-038
i = struct.unpack('>l', rgb)[0]
# you can get back the float value by the inverse operations
pack = ctypes.c_uint32(i).value
r = (pack & 0x00FF0000) >> 16
g = (pack & 0x0000FF00) >> 8
b = (pack & 0x000000FF)