Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
Point Cloud Utilities

Point Cloud Rectification

After creating a calibrated point cloud, a gapless rectified point cloud often is required to enable 2D image processing. The process for achieving this is outlined in the following sections.

Creation of ZMaps

The following code snippet demonstrates how to rectify a point cloud (i.e., create a ZMap) by calculating its bounding box, specifying the rectification parameters, and generating the ZMap:

auto cloud = ...;
// Compute bounding box of cloud.
auto bb = cloud->CalculateBoundingBox(); // (1)
// Specify parameters for rectification.
int width = ...; // (2)
int height = ...;
double backgroundValue = 0.0;
// Rectify point cloud.
auto zmap = cloud->RangeMap(bb.XRange(), bb.YRange(), Cvb::Size2D<int>(width, height), backgroundValue); // (3)

// Compute bounding box of cloud.
var bb = cloud.CalculateBoundingBox(); // (1)
// Specify parameters for rectification.
int width = ...; // (2)
int height = ...;
var size = new Cvb.Size2D(width, height);
double backgroundValue = 0.0;
// Rectify point cloud.
var zmap = cloud.ToRangeMap(bb.X, bb.Y, size, backgroundValue); // (3)

# Compute bounding box of cloud.
bb = cloud.calculate_bounding_box() # (1)
# Specify parameters for rectification.
width = 10 # (2)
height = 10
backgroundValue = 0.0
# Rectify point cloud.
zmap = cloud.range_map(bb.x_range, bb.y_range, cvb.Size2D(width, height), backgroundValue) # (3)

(1) Compute the bounding box of your point cloud. It defines the region to be rectified in step (3). If you want to rectify only a smaller region, reduce the bounding box accordingly. Conversely, if you want to include a larger background area, you can enlarge it.
(2) Define the rectification parameters. You need to specify the width and height of the resulting ZMap. In practice, it is often more convenient to define the physical area to rectify and the desired pixel size. Based on that, the width and height can be calculated, as shown in the next code snippet.
(3) Perform the rectification.

The following C++ code snippet demonstrates how to compute the width and height of the ZMap based on a fixed area to rectify and a given pixel size:

// Function to calculate dimension based on range and pixel size.
int CalculateDimZmap(double pixelSize, const Cvb::ValueRange<double>& range)
{
auto dim = round((range.Max() - range.Min()) / pixelSize);
return static_cast<int>(dim);
}
// Area to rectify.
auto bb = ...;
// Desired pixel size (same units as X,Y, and Z coordinates of point cloud, i.e. usually mm).
double pixelSize = 0.05;
// Calculate width and height for output ZMap.
auto width = CalculateDimZmap(pixelSize, bb.XRange());
auto height = CalculateDimZmap(pixelSize, bb.YRange());
T Min() const noexcept
T Max() const noexcept

Gap Filling for ZMaps

After rectifying a calibrated point cloud, the resulting ZMap may contain small gaps. These gaps can be filled using the Cvb::FillGaps function, which applies linear interpolation, as shown in the example below:

#include <cvb/range_map.hpp>
auto zmap = ...;
auto options = Cvb::GapFillingOptions(0.0, 100, 100, Cvb::GapFillingMethod::LinearInterpolation);
Cvb::FillGaps(zmap->Plane(0), options);
void FillGaps(const ImagePlane &rangeMap, const GapFillingOptions &options)

var zmap = ...;
var options = new Cvb.GapFillingOptions(0.0, 100, 100, Cvb.GapFillingMethod.LinearInterpolation);
Cvb.Process.FillGaps(zmap.Planes[0], options);

zmap = ...
options = cvb.GapFillingOptions(0.0, 100, 100, cvb.GapFillingMethod.LinearInterpolation)
cvb.fill_gaps(zmap.planes[0], options)
None fill_gaps(cvb.ImagePlane range_map, cvb.GapFillingOptions options)

The resulting ZMap may then look like this:

zmap with gaps
ZMap with Gaps
zmap without gaps
ZMap without Gaps

Other Point Cloud Utilities

CVB provides a range of utility functions for working with point clouds, including:

  • Cropping (by bounding box, frustum, or plane)
  • Down-sampling and scaling
  • Applying affine transformations
  • Plane fitting
  • And more...

An overview of all available functions can be found in the following classes: