Home > Back-end >  Three-dimensional point cloud registration recently doing research, the following program compiled s
Three-dimensional point cloud registration recently doing research, the following program compiled s

Time:09-23

# include & lt; Boost/make_shared. Hpp>
# include & lt; Photo/point_types. H>
# include & lt; Photo/point_cloud. H>
# include & lt; Photo/point_representation. H>
# include & lt; Photo/IO/pcd_io. H>
# include & lt; Photo/filters/voxel_grid. H>
# include & lt; Photo/filters/filter. H>
# include & lt; Photo/features/normal_3d. H>
# include & lt; Photo/registration/icp. H>
# include & lt; Photo/registration/icp_nl. H>
# include & lt; Photo/registration/transforms. H>
# include & lt; Photo/visualization/pcl_visualizer. H>
Using photo: : the visualization: : PointCloudColorHandlerGenericField;
Using photo: : the visualization: : PointCloudColorHandlerCustom;
//a simple type definition
Typedef PCLS: : PointXYZ PointT;
Typedef PCLS: : PointCloud PointCloud.
Typedef PCLS: : PointNormal PointNormalT;
Typedef PCLS: : PointCloud PointCloudWithNormals;
//this is an auxiliary tutorial, so we can afford a global variable
//create a visual tool
Photo: the visualization: : PCLVisualizer * p;
//define viewpoints about
Int vp_1, vp_2;
//processing of point cloud and convenient structure definition
Struct PCD
{
PointCloud: : Ptr cloud;
STD: : string f_name;
PCD () : cloud (new PointCloud) {};
};
Struct PCDComparator
{
Boolean operator () (const PCD& P1, const PCD& P2)
{
Return (p1. F_name & lt; P2. F_name);
}
};
//to & lt; X, y, z, curvature & gt; Formal definition of a new point
The class MyPointRepresentation: public photo: : PointRepresentation & lt; PointNormalT>
{
Using photo: : PointRepresentation : : nr_dimensions_;
Public:
MyPointRepresentation ()
{
//define size
Nr_dimensions_=4;
}
//cover copyToFloatArray method to define our characteristic vector
Virtual void copyToFloatArray (const PointNormalT & amp; P, float * out) const
{
//& lt; X, y, z, curvature & gt;
The out [0]=p.x;
The out [1]=p.y;
The out [2]=p.z;
The out [3]=p.c urvature;
}
};
////////////////////////////////////////////////////////////////////////////////
/* * the first view in the visualization window shows the source point and target point cloud
*
*/
Void showCloudsLeft (const PointCloud: : Ptr cloud_target, const PointCloud: : Ptr cloud_source)
{
P - & gt; Vp1_target removePointCloud (" ");
P - & gt; Vp1_source removePointCloud (" ");
PointCloudColorHandlerCustom Tgt_h (cloud_target, 0, 255, 0).
PointCloudColorHandlerCustom Src_h (cloud_source, 255, 0, 0).
P - & gt; AddPointCloud (cloud_target tgt_h, "vp1_target vp_1);
P - & gt; AddPointCloud (cloud_source src_h, "vp1_source vp_1);
PCL_INFO (" Press q to begin the registration. \ n ");
P - & gt; Spin ();
}
////////////////////////////////////////////////////////////////////////////////
/* * in the second viewpoint of the visualization window display source point clouds and the target point cloud
*
*/
Void showCloudsRight (const PointCloudWithNormals: : Ptr cloud_target, const PointCloudWithNormals: : Ptr cloud_source)
{
P - & gt; RemovePointCloud (" source ");
P - & gt; RemovePointCloud (" target ");
PointCloudColorHandlerGenericField Tgt_color_handler (cloud_target, "curvature");
if (! Tgt_color_handler. IsCapable ())
PCL_WARN (" always create a curvature color handler!" );
PointCloudColorHandlerGenericField Src_color_handler (cloud_source, "curvature");
if (! Src_color_handler. IsCapable ())
PCL_WARN (" always create a curvature color handler!" );
P - & gt; AddPointCloud (cloud_target tgt_color_handler, "target", vp_2);
P - & gt; AddPointCloud (cloud_source src_color_handler, "the source", vp_2);
P - & gt; SpinOnce ();
}
////////////////////////////////////////////////////////////////////////////////
/* * to load a set of we want to match with the PCD file
* parameters arg c is the number of (pass from the main ())
* argv actual command-line parameters (pass from the main ())
* parameter models of point cloud data sets synthetic vector
*/
Void loadData (int arg c, char * * argv, STD: : vector & Models)
{
STD: : string extension (". PCD ");
//assume that the first parameter is the actual test model
For (int I=1; i {
STD: : string fname=STD: : string (argv [I]);
//will need at least 5 characters long. Because the plot of five characters)
If (fname. The size () & lt;=the extension. The size ()
continue;
STD: : transform (fname. The begin (), fname. The end (), fname. The begin (), (int (*) (int)) tolower);
//check parameter is a PCD file
If (fname.com pare said (fname. The size () - the extension. The size (), the extension, the size (), the extension)==0)
{
//loading point cloud and stored in the overall model list
PCD m;
M. _name=argv [I];
Photo: : IO: : loadPCDFile (argv [I], * m.c loud);
//removed from the point of the cloud point of NAN
STD: : vector Indices;
Photo: : removeNaNFromPointCloud (* m.c loud, * m.c loud, indices);
Models. The push_back (m);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/* * matched a pair of point cloud data sets and return the results
* parameters cloud_src is the source point cloud
Cloud_src * parameter is the target point cloud
* parameters output the output source point cloud registration results
* parameters final_transform is the conversion between source and target
*/
Void pairAlign (const PointCloud: : Ptr cloud_src, const PointCloud: : Ptr cloud_tgt, PointCloud: : Ptr output, Eigen: : Matrix4f & amp; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related