我如何将 float32 解释为 numpy 中的四个 uint8?
How can I interpret a float32 as four uint8s in numpy?
我尝试使用python读取扩展名为“.pcd”的点云数据文件。它们只用一个 numpy float32 存储 RGBA 颜色信息。
如何将 float32
数据类型转换为 python 中的 4 uint8
个数字?
比如数字4.51073351e-39隐藏的rgb值是多少?
In [13]: pc.pc_data["rgb"]
Out[13]:
array([ 4.51073351e-39, 4.41853788e-39, 4.87845245e-39, ...,
3.31220574e-39, 2.94594696e-39, 3.12997949e-39], dtype=float32)
这里是link下载数据集:http://rgbd-dataset.cs.washington.edu/dataset/rgbd-dataset_pcd_ascii/apple_1.tar
我用 pypcd 读取文件:这里是 pypcd github link:https://github.com/dimatura/pypcd
我想你想要 pc.pc_data["rgb"].view((np.uint8, 4))
,对于你的例子来说:
array([[23, 30, 49, 0],
[22, 29, 48, 0],
[36, 31, 53, 0],
...
[21, 17, 36, 0],
[26, 20, 32, 0],
[28, 21, 34, 0]], dtype=uint8)
晚会真的晚了,但是pypcd(这里是作者)实际上有这个功能decode_rgb_from_pcl
,你可以称它为pypcd.decode_rgb_from_pcl(pc.pc_data['rgb'])
。无可否认,我比我更喜欢@Eric 的实现方式 :D
我尝试使用python读取扩展名为“.pcd”的点云数据文件。它们只用一个 numpy float32 存储 RGBA 颜色信息。
如何将 float32
数据类型转换为 python 中的 4 uint8
个数字?
比如数字4.51073351e-39隐藏的rgb值是多少?
In [13]: pc.pc_data["rgb"]
Out[13]:
array([ 4.51073351e-39, 4.41853788e-39, 4.87845245e-39, ...,
3.31220574e-39, 2.94594696e-39, 3.12997949e-39], dtype=float32)
这里是link下载数据集:http://rgbd-dataset.cs.washington.edu/dataset/rgbd-dataset_pcd_ascii/apple_1.tar
我用 pypcd 读取文件:这里是 pypcd github link:https://github.com/dimatura/pypcd
我想你想要 pc.pc_data["rgb"].view((np.uint8, 4))
,对于你的例子来说:
array([[23, 30, 49, 0],
[22, 29, 48, 0],
[36, 31, 53, 0],
...
[21, 17, 36, 0],
[26, 20, 32, 0],
[28, 21, 34, 0]], dtype=uint8)
晚会真的晚了,但是pypcd(这里是作者)实际上有这个功能decode_rgb_from_pcl
,你可以称它为pypcd.decode_rgb_from_pcl(pc.pc_data['rgb'])
。无可否认,我比我更喜欢@Eric 的实现方式 :D