Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PointCloud2 Packs Bits Incorrectly #76

Open
DLu opened this issue Jul 19, 2015 · 0 comments
Open

PointCloud2 Packs Bits Incorrectly #76

DLu opened this issue Jul 19, 2015 · 0 comments
Labels

Comments

@DLu
Copy link
Contributor

DLu commented Jul 19, 2015

The Python library for writing point clouds has some weird bit-packing issues.

Consider writing this script for writing colors:

from sensor_msgs.point_cloud2 import create_cloud
from sensor_msgs.msg import PointField
import struct

fields = []
fields.append( PointField('rgb', 0, PointField.FLOAT32, 1) )

def pack_bytes(r,g,b,a):
    print 'original:', [b,g,r,a]
    x = (a << 24) + (r << 16) + (g << 8) + b
    a = struct.unpack('f', struct.pack('I', x))[0]

    points = [ (a, )]

    nc = create_cloud(None, fields, points)

    print 'packed  :', [ord(x) for x in nc.data]
    print


pack_bytes(120,0,0,0)
pack_bytes(120,0,0,255)

pack_bytes(130,0,0,0)
pack_bytes(130,0,0,255)

This outputs:

original: [0, 0, 120, 0]
packed  : [0, 0, 120, 0]

original: [0, 0, 120, 255]
packed  : [0, 0, 120, 255]

original: [0, 0, 130, 0]
packed  : [0, 0, 130, 0]

original: [0, 0, 130, 255]
packed  : [0, 0, 194, 255]

There is a bug where if red value is over 127 and the alpha value is 255, the output values do not match the input values.

I realize that the alpha is not necessarily supported, but I found it in a bag file (from a kinect I believe) and it was causing problems.

@tfoote tfoote added the bug label May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants