utiasSTARS / pykitti

Python tools for working with KITTI data.
MIT License
1.15k stars 239 forks source link

Using numpy.fromfile might be platform-dependent? #46

Open m-lit opened 5 years ago

m-lit commented 5 years ago

According to the official documentation, numpy.fromfile assumes platform-dependent binary format, and hence, it should not be used to transfer data from machines with different architectures.

The load_velo_scan is currently defined as:

def load_velo_scan(file):
    """Load and parse a velodyne binary file."""
    scan = np.fromfile(file, dtype=np.float32)
    return scan.reshape((-1, 4))

I am concerned about using the function to load data from the velodyne bin files provided by KITTI. Is this approach guaranteed to work regardless of the CPU architecture on which the code is being run?

valgur commented 5 years ago

I'm not sure how np.fromfile() works on big-endian machines, but I agree, it would not hurt to use dtype='<f4' to set the data type explicitly to little-endian single-precision float.