PCL Series-Stitching two point clouds

Source: Internet
Author: User
Tags rand strcmp

Welcome to visit our blog PCL Series PCL Series--read in PCD format File Operation PCL Series--writing point cloud Data to PCD format File PCL series--stitching two point clouds PCL series--extracting Narf key points from depth image (Rangeimage) PCL series--how to visualize depth image PCL series-- How to use the iterative nearest point method (ICP) Registration PCL Series--How to gradually register a pair of point clouds PCL series--three-dimensional reconstruction of Poisson reconstruction PCL series--three-dimensional reconstruction of greedy triangular projection algorithm PCL series--three-dimensional reconstruction of moving cube algorithm description

Through this tutorial, we will learn to:
* How to stitch two points of different point clouds, the constraint is that the number and type of fields in two datasets must be equal. * How to stitch two different point cloud domains, the constraint is that the number of points in a data set must be equal. Action Create a new file Concatenate_clouds.cpp in VS2010, and then copy the following code to the file. Refer to the previous article to configure the properties of the item. Sets the Include directory and Library directory and additional dependencies.

#include <iostream>//Standard input/output stream #include <pcl/io/pcd_io.h>//pcl of the input and output header file of the PCD format file #include <pcl/point_ Types.h>//PCL Support header file for various format points//For example, your program encounters a threat that the call stack is running out. You say, where do you borrow the memory,//store your error message. The purpose of Cerr is to get support for the output function in the case of emergencies that you need most. The purpose of the buffer is to reduce the number of brush screen//program splicing A and B to C int main (int argc, char** argv) {if (argc! = 2)//requires a parameter-F or-p {std::cerr &lt
    ;< "Specify command line ARG '-f ' or '-P '" << Std::endl;
  Exit (0); }//variable for stitching points of different point clouds PCL::P OINTCLOUD&LT;PCL::P ointxyz> cloud_a, cloud_b, Cloud_c; Create a point cloud (not a pointer), store point coordinates xyz//variable PCL used to stitch domains (points and normals) of different point clouds::P ointcloud<pcl::normal> n_cloud_b; Create point cloud, store normal vector PCL::P OINTCLOUD&LT;PCL::P ointnormal> P_n_cloud_c; Create point clouds, store point coordinates and normal vector//fill point cloud data cloud_a.width = 5; Set width cloud_a.height = cloud_b.height = N_cloud_b.height = 1; Set height cloud_a.points.resize (cloud_a.width * cloud_a.height); Deform, unordered if (strcmp (argv[1], "-p") = = 0)//based on input parameters, set point cloud {cloud_b.width = 3;//cloud_b points for stitching different point clouds cloud_b.points . REsize (Cloud_b.width * cloud_b.height); 
  } else{n_cloud_b.width = 5;//n_cloud_b the domain n_cloud_b.points.resize (n_cloud_b.width * n_cloud_b.height) used to stitch different point clouds; } for (size_t i = 0; i < cloud_a.points.size (); ++i)//Set the coordinates of the cloud_a midpoint (random number) {cloud_a.points[i].x = 1024x768 * r
    and ()/(Rand_max + 1.0f);
    CLOUD_A.POINTS[I].Y = 1024x768 * RAND ()/(Rand_max + 1.0f);
  CLOUD_A.POINTS[I].Z = 1024x768 * RAND ()/(Rand_max + 1.0f); 
      if (strcmp (argv[1], "-p") = = 0) for (size_t i = 0; i < cloud_b.points.size (); ++i)//Set the coordinates of the cloud_b midpoint (random number) {
      cloud_b.points[i].x = 1024x768 * RAND ()/(Rand_max + 1.0f);
      CLOUD_B.POINTS[I].Y = 1024x768 * RAND ()/(Rand_max + 1.0f);
    CLOUD_B.POINTS[I].Z = 1024x768 * RAND ()/(Rand_max + 1.0f); } else//-F for (size_t i = 0; i < n_cloud_b.points.size (); ++i)//Set the coordinates of the midpoint of the n_cloud_b (random number) {n_cloud_b.
      POINTS[I].NORMAL[0] = 1024x768 * RAND ()/(Rand_max + 1.0f); N_CLOUD_B.POINTS[I].NORMAL[1] = 1024x768 * RAND ()/(Rand_MAX + 1.0f);
    N_CLOUD_B.POINTS[I].NORMAL[2] = 1024x768 * RAND ()/(Rand_max + 1.0f);
  }//Print stitching with data A and B std::cerr << "Cloud A:" << Std::endl; for (size_t i = 0; i < cloud_a.points.size (); ++i)//print cloud_a point coordinate information std::cerr << "" << Cloud_a.po

  ints[i].x << "<< cloud_a.points[i].y <<" "<< cloud_a.points[i].z << Std::endl; Std::cerr << "Cloud B:" << Std::endl; Print Cloud B if (strcmp (argv[1], "-p") = = 0)//If the input parameter is-p, print cloud_b; for (size_t i = 0; i < cloud_b.points.size (); ++i) std::cerr << "<< cloud_b.points[i].x <<" "<< cloud_b.points[i].y <<" "&
  lt;< cloud_b.points[i].z << Std::endl; else//If-F, print n_cloud_b for (size_t i = 0; i < n_cloud_b.points.size (); ++i) Std::cerr << "" &LT;&L T N_cloud_b.points[i].normal[0] << "<< n_cloud_b.points[i].normal[1] <<" "<< n_cloud_b.points [I].NORMAL[2] << Std::endl;
    The point in the copy Point cloud, if (strcmp (argv[1], "-p") = = 0) {Cloud_c = cloud_a; Cloud_c + = Cloud_b; Cloud_a + Cloud_b means Cloud_c contains points in A and B, C points = Points of a +b points std::cerr << "cloud C:" << Std::endl; Print Cloud C for (size_t i = 0; i < cloud_c.points.size (); ++i)//Print cloud C std::cerr << "<& Lt cloud_c.points[i].x << "<< cloud_c.points[i].y <<" "<< cloud_c.points[i].z <<" "<& Lt
  Std::endl; } else//If the input parameters are-f {pcl::concatenatefields (cloud_a, N_cloud_b, P_n_cloud_c);//splicing (points) cloud_a and (normal vector) n_cloud_b to P_N_CL
    Oud_c std::cerr << "Cloud C:" << Std::endl; for (size_t i = 0; i < p_n_cloud_c.points.size (); ++i)//Print cloud C std::cerr << "<< p_ n_cloud_c.points[i].x << "<< p_n_cloud_c.points[i].y <<" "<< p_n_cloud_c.points[i].z <&lt ; "" << P_n_cloud_c.points[i].normal[0] <&lT
  "<< p_n_cloud_c.points[i].normal[1] <<" "<< p_n_cloud_c.points[i].normal[2] << Std::endl;
} return (0); }
Rebuild the project. To change the project's debug directory, hold down SHIFT while you click the right mouse button to open the Cmd window in the current window. In the cmd window, enter the command concatenate_clouds.exe-p, execute stitching points of different point clouds。 The result is shown in the following figure.
In the cmd window, enter the command concatenate_clouds.exe-f, execute fields with different point clouds (such as points and normal vectors)。 The result is shown in the following figure.
ReferenceConcatenate the points of both point Clouds

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.