2

I tried to use python to read points cloud data files, which with extension ".pcd". They store RGBA color information with just one numpy float32. How can i convert the float32 data type into 4 uint8 numbers in python ? For example, what is the rgb value hidden in number 4.51073351e-39 ?

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)

Here is the link to download the dataset: http://rgbd-dataset.cs.washington.edu/dataset/rgbd-dataset_pcd_ascii/apple_1.tar

And i used pypcd to read the file: here is the pypcd github link:https://github.com/dimatura/pypcd

Eric
  • 95,302
  • 53
  • 242
  • 374
Tang
  • 303
  • 3
  • 12

2 Answers2

2

I think you want pc.pc_data["rgb"].view((np.uint8, 4)), which for your example gives:

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)
Eric
  • 95,302
  • 53
  • 242
  • 374
1

Really late to the party, but pypcd (author here) actually has this function as decode_rgb_from_pcl, you can call it as pypcd.decode_rgb_from_pcl(pc.pc_data['rgb']). Admittedly, I like the way @Eric implemented this better than mine :D