Skip to content

bplus-group/pandaset2bag

Repository files navigation


Logo

pandaset2bag

Command-line utility (and Python library) for converting the PandaSet Dataset to ROS2 bag files
Quickstart · Report Bug · Request Feature


LinkedIn Stars

Table of Contents
  1. Quickstart
  2. Using pandaset2bag with Foxglove
  3. Coordinate system
  4. Annotations
  5. Contributing
  6. License

pandaset2bag

Quickstart

Installation

With the use of the Python library Rosbags which does not have any dependencies on the ROS2 software stacks, pandaset2bag can be used without the need to install ROS2. pandaset2bag requires an installation of Python 3.10+, as well as pip. Other dependencies can be found in the requirements.txt.

To install from source with pip:

$ python3 -m pip install git+https://github.com/bplus-group/pandaset2bag

Back to top

Configuration

Per default, pandaset2bag uses the Marker.msg definition before the marker textures were added on Aug 2021 to support the visualization of the generated bag files via Foxglove. To use the updated Marker.msg definition, you can set the UPDATED_VISUALIZATION_MSG_MARKER environment variable to true:

export UPDATED_VISUALIZATION_MSG_MARKER=true


When calling the converter, the used Marker.msg definition will be displayed at the beginning:

█████ Using DEFAULT/UPDATED visualization_msgs


See below for details on using pandaset2bag with Foxglove.

Back to top

Using the command-line interface

basic example

$ pandaset2bag --dataset-dir /data/pandaset --sequence-id 2 --output pandasetbag_002
█████ Using UPDATED visualization_msgs
Converting cameras... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:06
Converting GPS... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Converting pandar64 lidar... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:01
Converting pandarGT lidar... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:01
Converting cuboids... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:05
Generating /tf for ego_vehicle... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Generating /tf for left_camera... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Generating /tf for front_right_camera... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Generating /tf for front_camera... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Generating /tf for right_camera... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Generating /tf for back_camera... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Generating /tf for front_left_camera... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Generating /tf for pandar64... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Generating /tf for pandarGT... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00

advanced example

  • resizing images to 1280x720
  • use JPEG compression for the corresponding topics
$ pandaset2bag --dataset-dir /data/pandaset \
               --sequence-id 2 \
               --max-image-size 1280 \
               --type compressed \
               --output pandasetbag_002

Options

For more advanced options while converting:

  -h, --help            show this help message and exit
  -d DATASET_DIR, --dataset-dir DATASET_DIR
                        the directory path of the dataset (default: None)
  -i SEQUENCE_ID, --sequence-id SEQUENCE_ID
                        the ID of the sequence to be converted (default: None)
  -o OUTPUT, --output OUTPUT
                        the save path of the rosbag file; if '', i.e the rosbag file will be saved
                        in the current working directory with the name 'pandasetbag_{sequence_id}'
                        (default: )
  -s MAX_IMAGE_SIZE [MAX_IMAGE_SIZE ...], --max-image-size MAX_IMAGE_SIZE [MAX_IMAGE_SIZE ...]
                        maximum image size to convert to (default: [])
  -t {raw,compressed,raw_compressed}, --type {raw,compressed,raw_compressed}
                        type to be used to convert an image (default: raw)
  -f {jpeg,png}, --format {jpeg,png}
                        image format used for compression (default: jpeg)
  -q JPEG_QUALITY, --jpeg-quality JPEG_QUALITY
                        image compression quality for JPEG format; the image quality, on a scale
                        from 0 (worst) to 95 (best), or the string keep. Values above 95 should be
                        avoided; 100 disables portions of the JPEG compression algorithm, and
                        results in large files with hardly any gain in image quality; the value keep
                        is only valid for JPEG files and will retain the original image quality
                        level, subsampling, and qtables (default: 75)
  -l {0,1,2,3,4,5,6,7,8,9}, --png-compress-level {0,1,2,3,4,5,6,7,8,9}
                        image compression level for PNG format; ZLIB compression level, a number
                        between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no
                        compression at all. When optimize option is True compress_level has no
                        effect (it is set to 9 regardless of a value passed); the value is only
                        valid for PNG files and will be otherwise ignored (default: 6)
  -O, --png-optimize    image optimization status for PNG format; if True, instructs the PNG writer
                        to make the output file as small as possible; this includes extra processing
                        in order to find optimal encoder settings; the value is only valid for PNG
                        files and will be otherwise ignored (default: False)
  -m {none,file,message}, --mode {none,file,message}
                        compression mode for rosbag file. (default: none)
  -c, --cuboids         save cuboids `DataFrame` status; if True, save the converted cuboids
                        `DataFrame`'s as `.pkl.gz` files, representing the properties of the cuboids
                        in normalized ego coordinates (default: False)
  -v, --version         show program's version number and exit

Back to top

Using pandaset2bag in a Python script

basic example

from pandaset2bag.pandaset2bag_converter import PandaSet2BagConverter

converter = PandaSet2BagConverter('./data/pandaset')

sequence_id = '002'
converter.convert(sequence_id)

advanced example

  • resizing images to 1280x720
  • convert the image both as Image.msg and as CompressedImage.msg
  • use JPEG compression for the corresponding topics
  • enable compression (equivalent to ros2 bag ... --compression-mode file)
from pandaset2bag.pandaset2bag_converter import PandaSet2BagConverter
from pandaset2bag.enums import CompressedImageFormat, ImageConvertType
from rosbags.rosbag2 import Writer

converter = PandaSet2BagConverter('./data/pandaset')

converter.image_convert_type = ImageConvertType.RAW_COMPRESSED
converter.image_format = CompressedImageFormat.JPEG
converter.max_image_size = (1280, 720)
converter.compression_mode = Writer.CompressionMode.FILE

sequence_id = '002'
converter.convert(sequence_id)

Back to top

Using pandaset2bag with Foxglove

As mentioned before, to visualize the generated bag files (.db3; sqlite3 storage plugin) with Foxglove, use the Marker.msg definition set as default.

Warning Foxglove does not support the playback of compressed (.db3) bag files.

For increased performance during playback or to support the compression of bag files, the use of MCAP is recommended. For conversion from .db3 to .mcap, the corresponding MCAP CLI provided by Foxglove can be used.

Warning MCAP CLI uses the updated Marker.msg definition so you have to set the UPDATED_VISUALIZATION_MSG_MARKER environment variable to true while converting a sequence from the PandaSet using pandaset2bag.

Back to top

Coordinate system

It is important to note that in the PandaSet dataset, all point cloud data is referenced to a global coordinate system and not an ego coordinate system. See arXiv:2112.12610 for more details.

Using pandaset2bag all data will refer to an ego coordinate system where the coordinates are transformed to a unified normative coordinate system, such that the x-axis corresponds positive to the front direction, the y-axis corresponds positive to the left direction, and the z-axis corresponds positive to the top direction.

Back to top

Annotations

Cuboids

The LiDAR cuboid annotations can be accessed as JSON string through the text property of a Marker.msg from the /panda/markers topic of each scene/sequence. Using pandas.DataFrame.to_json with orient='table', the string also includes the JSON schema.

Additionally there is the option to export the LiDAR cuboid annotations as pandas.DataFrame (see options using the pandaset2bag CLI as an example). Using pandas.DataFrame.to_pickle with compression='gzip' the exported cuboid annotations are fully compatible with the pandaset-devkit.

Back to top

Semantic segmentation

Similary the semantic segmentation annotations can be accessed through the binary data blob of a PointCloud2.msg from the corresponding LiDAR topic (e.g. /panda/ego_vehicle/pandar64) of each scene. Each PointCloud2.msg has an additional channel (PointField.msg) for the class ID of the semantic segmentation result. The channels of a PointCloud2.msg are x, y, z, intensity and class_id each of datatype FLOAT32.

Note Not all scenes of the PandaSet have semantic segmentation annotations. In that case, the class ID is set to -1.


Using Foxglove you can color the point cloud by the class_id using the 'Color by' option under the correspondig LiDAR topic.

Back to top

Contributing

If you have a suggestion that would improve this, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/NewFeature)
  3. Commit your Changes (git commit -m 'Add some NewFeature')
  4. Push to the Branch (git push origin feature/NewFeature)
  5. Open a Pull Request

Back to top

License

All code, unless otherwise noted, is licensed under the MIT License. See LICENSE for more information.

Back to top