Point Clouds (LiDAR)

Introduction

In this tutorial we will focus on working with Point Clouds and Point Cloud Episodes using Supervisely SDK.

You will learn how to:

πŸ“— Everything you need to reproduce this tutorial is on GitHub: source code and demo data.

How to debug this tutorial

Step 1. Prepare ~/supervisely.env file with credentials. Learn more here.

Step 2. Clone repository with source code and demo data and create Virtual Environment.

git clone https://github.com/supervisely-ecosystem/tutorial-pointclouds.git

cd tutorial-pointclouds

./create_venv.sh

Step 3. Open repository directory in Visual Studio Code.

Step 4. Change workspace ID in local.env file by copying the ID from the context menu of the workspace.

Step 5. Start debugging src/main.py.

Import libraries

Init API client

First, we load environment variables with credentials and init API for communicating with Supervisely Instance.

Get variables from environment

In this tutorial, you will need an workspace ID that you can get from environment variables. Learn more here

Create new project and dataset

Create new project.

Source code:

Output:

Create new dataset.

Source code:

Output:

Upload point clouds and photo context to Supervisely

Upload single point cloud.

Source code:

Output:

first-pcd-uploaded

Now you can explore and label it in Supervisely labeling tool:

first-in-labeling-tool

Extrinsic and intrinsic matrices

If you have a photo context taken with a LIDAR image, you can attach the photo to the point cloud. To do that, we need two additional matrices. They are used for matching 3D coordinates in the point cloud to the 2D coordinates in the photo context:

matrices_labeled

Parameters meaning

  • fx, fy are the focal lengths expressed in pixel units

  • cx, cy is a principal point that is usually at the image center

  • rij and ti from the extrinsicMatrix are the rotation and translation parameters

The dot product of the matrices and XYZ coordinate in 3D space gives us the coordinate of a point (x=u, y=v) in the photo context:

dot_product_matrices

Uploading context photo to the Supervisely.

For attaching a photo, it is needed to provide the matrices in a meta dict with the deviceId and sensorsData fields. The matrices must be included in the meta dict as flattened lists.

Example of a meta dict:

A full code for uploading and attaching the context image

Source code:

Output:

first-in-labeling-tool-context

More about the format of a photo context: Supervisely annotation JSON format

More about calibration and matrix transformations: OpenCV 3D Camera Calibration Tutorial.

Upload list of point clouds and context images.

βœ… Supervisely API allows uploading multiple point clouds in a single request. The code sample below sends fewer requests and it leads to a significant speed-up of our original code.

Source code:

Output:

Get info by name

Get information about point cloud from Supervisely by name.

Source code:

Output:

Get info by ID

You can also get information about image from Supervisely by id.

Source code:

Output:

Get information about context images

Get information about related context images. For example it can be a photo from front/back cameras of a vehicle.

Source code:

Output:

Get photocontext's 2D figure list

You can get list of 2D figure on a pointcloud photo context:

Source code:

Output:

Get list of all point clouds in the dataset

You can list all point clouds in the dataset.

Source code:

Output:

Download point clouds and context images from Supervisely

Download a point cloud

Download point cloud from Supervisely to local directory by id.

Source code:

Output:

Download a related context image from Supervisely to local directory by image id.

Source code:

Output:

Working with Point Cloud Episodes

Working with Point Cloud Episodes is similar, except the following:

  1. There is api.pointcloud_episode for working with episodes.

  2. Create new projects with type sly.ProjectType.POINT_CLOUD_EPISODES.

  3. Put the frame index in meta while uploading a pcd: meta = {"frame": idx}.

Note: in Supervisely each episode is treated as a dataset. Therefore, create a separate dataset every time you want to add a new episode.

Create new project and dataset

Create new project.

Source code:

Output:

Create new dataset.

Source code:

Output:

Upload one point cloud to Supervisely.

Source code:

Output:

Upload entire point clouds episode to Supervisely platform.

Source code:

Output:

Now you can explore and label it in Supervisely labeling tool for Episodes:

episodes

Last updated

Was this helpful?