【问题标题】:How can I interpret a float32 as four uint8s in numpy?如何在 numpy 中将 float32 解释为四个 uint8?
【发布时间】:2017-03-08 01:16:47
【问题描述】:

我尝试使用 python 读取扩展名为“.pcd”的点云数据文件。他们只用一个 numpy float32 存储 RGBA 颜色信息。 如何在 python 中将float32 数据类型转换为 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)

这里是下载数据集的链接:http://rgbd-dataset.cs.washington.edu/dataset/rgbd-dataset_pcd_ascii/apple_1.tar

我使用 pypcd 读取文件:这里是 pypcd github 链接:https://github.com/dimatura/pypcd

【问题讨论】:

标签: python numpy bitwise-operators


【解决方案1】:

我想你想要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)

【讨论】:

    【解决方案2】:

    真的迟到了,但是pypcd(作者在这里)居然有这个功能decode_rgb_from_pcl,你可以叫它pypcd.decode_rgb_from_pcl(pc.pc_data['rgb'])。诚然,我比我更喜欢@Eric 实现这一点的方式:D

    【讨论】:

      猜你喜欢
      • 2018-08-24
      • 2020-03-27
      • 2022-01-15
      • 2021-11-29
      • 2020-05-16
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      相关资源
      最近更新 更多