Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
Image Manager/Cvb++/CppPointCloudCreateCalibrated

This example program is located in your CVB installation under %CVB%Tutorial/Image Manager/Cvb++/CppPointCloudCreateCalibrated.

main.cpp:

// This example program shows how to create a calibrated point cloud with given calibration file and
// how to work with it.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include <iostream>
#include "cvb/point_cloud_factory.hpp"
#include "cvb/point_cloud.hpp"
#include "cvb/calibrator_3d.hpp"
Cvb::Plane3D CutAqs12RoofAndCalculateNormal(const Cvb::PointCloud& cloud, double zRangeRoof, double xRangeRoofPlane, double yRangeRoofPlane);
int main()
{
try
{
auto path = Cvb::InstallPath();
// create calibrated point cloud
Cvb::ImagePtr rangemap = Cvb::Image::Load(path + CVB_LIT("tutorial/Metric/Images/RangeMapCalibrationPattern.tif"));
auto calibrator = Cvb::Calibrator3D::Load<Cvb::Calibrator3D>(path + CVB_LIT("tutorial/Metric/Images/SICalibration.json"));
calibrator->SetRangeMapIgnoreValue(0.0);
auto cloudAqs12 = Cvb::PointCloudFactory::Create(rangemap->Plane(0), *calibrator,
Cvb::PointCloudFlags::Float | Cvb::PointCloudFlags::XYZ);
// do something, e.g.
// cut roof part of AQS12 and calculate its normal
auto plane = CutAqs12RoofAndCalculateNormal(*cloudAqs12, 10.0, 50.0, 1000.0);
}
catch (const std::exception & error)
{
std::cout << error.what() << std::endl;
}
return 0;
}
Cvb::Plane3D CutAqs12RoofAndCalculateNormal(const Cvb::PointCloud &cloud, double zRangeRoof, double xRangeRoofPlane, double yRangeRoofPlane)
{
auto dx = xRangeRoofPlane / 2;
auto dy = yRangeRoofPlane / 2;
// crop roof roughly
auto bbRoof = cloud.CalculateBoundingBox();
bbRoof.SetZRange({ bbRoof.ZRange().Max() - zRangeRoof, bbRoof.ZRange().Max() + 1 });
auto roof = cloud.Crop<Cvb::DensePointCloud>(bbRoof);
// use only midmost part of roof
auto cog = roof->CalculateCenterOfGravity();
auto bbRoofPlane = roof->CalculateBoundingBox();
bbRoofPlane.SetXRange({ cog.X() - dx, cog.X() + dx });
bbRoofPlane.SetYRange({ cog.Y() - dy, cog.Y() + dy });
auto roofPlane = roof->Crop(bbRoofPlane);
// calculate and return plane
return roof->FitPlane();
}
static std::shared_ptr< T > Load(const String &fileName)
void SetZRange(ValueRange< double > zRange) noexcept
static std::unique_ptr< Image > Load(const String &fileName)
static PointCloudPtr Create(const ImagePlane &rangeMap, const Calibrator3D &calibrator, PointCloudFlags flags)
std::shared_ptr< T > Crop(const Cuboid &clipBox) const
Cuboid CalculateBoundingBox() const
Point3D< double > CalculateCenterOfGravity() const
std::shared_ptr< Image > ImagePtr
String InstallPath()