[New-bugs-announce] [issue42494] struct.unpack_from return 2 values instead of one

Sébastien Lemetter report at bugs.python.org
Sat Nov 28 16:19:50 EST 2020


New submission from Sébastien Lemetter <sebaleme at gmail.com>:

Hi,

I am using an old version, but maybe you can still help me. I am using the ROS operating system, and there, the unpack_from function is used for reading values from bags.
When I try to read uint16 with the function pointcloud2.readpoint(), it returns 2 values instead of 1, and I couldn t understand why. Since this readpoint() is from the official pointcloud2 package from ros, and unpack_from is from official struct package, I don t think I could do many error here. In the screenshot, you can see that the inputs parameters seems ok. I am reading a field from my bag which is 2 bytes, and the offset (12) make also sense (4th value after 3 floats).



def read_points(cloud, field_names=None):

    """

    Read points from a L{sensor_msgs.PointCloud2} message.

 

    @param cloud: The point cloud to read from.

    @type  cloud: L{sensor_msgs.PointCloud2}

    @param field_names: The names of fields to read. If None, read all fields. [default: None]

    @type  field_names: iterable

    @param skip_nans: If True, then don't return any point with a NaN value.

    @type  skip_nans: bool [default: False]

    @param uvs: If specified, then only return the points at the given coordinates. [default: empty list]

    @type  uvs: iterable

    @return: Generator which yields a list of values for each point.

    @rtype:  generator

    """

    assert isinstance(cloud, roslib.message.Message) and cloud._type == 'sensor_msgs/PointCloud2', 'cloud is not a sensor_msgs.msg.PointCloud2'

    fmt = _get_struct_fmt(cloud.is_bigendian, cloud.fields, field_names)

    print('fmt size ' , str(struct.calcsize(fmt)))

    print('cloud.height ' , str(cloud.height))

    print('cloud.row_step ' , str(cloud.row_step))

    width, height, point_step, row_step, data, isnan = cloud.width, cloud.height, cloud.point_step, cloud.row_step, cloud.data, math.isnan

    unpack_from = struct.Struct(fmt).unpack_from

 

    for v in range(height):

        offset = row_step * v

        for u in range(width):      

            yield unpack_from(data, offset)

            offset += point_step

def callback(data):

    print("pointcloud size is %d bytes" % len(data.data))

    pointCloudArray_a = [1,2,3,4,5]

    #print((data.data.size))

    for indoux in range(4):

        print("==========================")

        print(indoux)

        pointCloudArray_a[indoux] = np.array(list((read_points2(data, field_names=(fields_PI6[indoux])))))

Here my mail again if you need more infos:
sebaleme at gmail.com

thanks,

----------
files: getIntensity.png
messages: 382017
nosy: sebaleme
priority: normal
severity: normal
status: open
title: struct.unpack_from return 2 values instead of one
type: behavior
Added file: https://bugs.python.org/file49632/getIntensity.png

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42494>
_______________________________________


More information about the New-bugs-announce mailing list