ROS2-Point-Cloud-Demo icon indicating copy to clipboard operation
ROS2-Point-Cloud-Demo copied to clipboard

The o3d.utility.Vector3dVector() line throws a runtime error without any description

Open dasiths opened this issue 3 years ago • 3 comments

The o3d.utility.Vector3dVector() line throws a runtime error without any description.

I'm guessing it's something to do with the conversion in pcd_as_numpy_array . The line doesn't throw an error though.

This alternative works though.

        gen = read_points(msg, skip_nans=True)
        int_data = list(gen)

        xyz = np.empty((len(int_data), 3))
        rgb = np.empty((len(int_data), 3))
        idx = 0
        for x in int_data:
            test = x[3] 
            # cast float32 to int so that bitwise operations are possible
            s = struct.pack('>f' ,test)
            i = struct.unpack('>l',s)[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)
            # prints r,g,b values in the 0-255 range
                        # x,y,z can be retrieved from the x[0],x[1],x[2]
            # xyz = np.append(xyz,[[x[0],x[1],x[2]]], axis = 0)
            # rgb = np.append(rgb,[[r,g,b]], axis = 0)
            xyz[idx] = [x[0],x[1],x[2]]
            rgb[idx] = [r,g,b]
            idx = idx + 1

        out_pcd = o3d.geometry.PointCloud()    
        out_pcd.points = o3d.utility.Vector3dVector(xyz)
        out_pcd.colors = o3d.utility.Vector3dVector(rgb)

dasiths avatar Oct 24 '22 07:10 dasiths

Thanks! I'll look into it when I have time :)

SebastianGrans avatar Oct 25 '22 06:10 SebastianGrans

This is an example point cloud message that causes the issue

header:
  stamp:
    sec: 1663547339
    nanosec: 244285720
  frame_id: map
height: 1
width: 54807
fields:
- name: x
  offset: 0
  datatype: 7
  count: 1
- name: y
  offset: 4
  datatype: 7
  count: 1
- name: z
  offset: 8
  datatype: 7
  count: 1
- name: id
  offset: 12
  datatype: 7
  count: 1
- name: sphericity
  offset: 16
  datatype: 7
  count: 1
is_bigendian: false
point_step: 20
row_step: 1096140
data:
- 175
- 5
- 145
- 64
- 207
- 131
- 230
- 65
- 232
- 51
- 206
- 64
- 0
- 0
- 0
- 0
- 171
- 105
- 66
- 62
- 154
- 33
- 186
- 64
- 14
- 28
- 226
- 65
- 162
- 115
- 246
- 64
- 0
- 0
- 0
- 0
- 219
- 124
- 200
- 62
- 118
- 181
- 147
- 64
- 206
- 230
- 227
- 65
- 150
- 220
- 197
- 64
- 0
- 0
- 0
- 0
- 148
- 199
- 65
- 62
- 94
- 179
- 240
- 64
- 234
- 25
- 241
- 65
- 3
- 155
- 56
- 64
- 0
- 0
- 0
- 0
- 80
- 197
- 21
- 62
- 51
- 183
- 22
- 65
- 205
- 158
- 207
- 65
- 38
- 131
- 156
- 64
- 0
- 0
- 0
- 0
- 247
- 55
- 154
- 62
- 249
- 200
- 255
- 64
- 84
- 210
- 241
- 65
- 143
- 32
- 29
- 64
- 0
- 0
- 0
- 0
- 37
- 201
- 178
- 62
- 8
- 203
- 35
- 65
- 5
- 200
- 205
- 65
- '...'
is_dense: false
---

dasiths avatar Oct 26 '22 02:10 dasiths

Potential solution https://gist.github.com/SebastianGrans/6ae5cab66e453a14a859b66cd9579239?permalink_comment_id=4354656#gistcomment-4354656

dasiths avatar Nov 01 '22 13:11 dasiths