PCL Series--Poisson reconstruction of three-dimensional reconstruction

Source: Internet
Author: User

PCL series
    • PCL Series--read in the PCD format file operation
    • PCL Series--writing point cloud data to a 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 images
    • 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--Poisson reconstruction of three-dimensional 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:

    • If the Poisson algorithm is used for three-dimensional point cloud reconstruction.
    • The program supports two file formats: *.pcd*.ply
    • The program reads the point cloud file, calculates the normal vector, then reconstructs it using the Poisson algorithm, and finally shows the result.
Operation
    • Create a new file in VS2010 recon_poisson.cpp , 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.
header file for the type of//point#include <pcl/point_types.h>//Point cloud File IO (PCD files and ply files)#include <pcl/io/pcd_io.h>#include <pcl/io/ply_io.h>//KD Tree#include <pcl/kdtree/kdtree_flann.h>//Feature Extraction#include <pcl/features/normal_3d_omp.h>#include <pcl/features/normal_3d.h>// refactoring#include <pcl/surface/gp3.h>#include <pcl/surface/poisson.h>//Visualization#include <pcl/visualization/pcl_visualizer.h>//Multithreading#include <boost/thread/thread.hpp>#include <fstream>#include <iostream>#include <stdio.h>#include <string.h>#include <string>intMainintargcChar* * argv) {//Determine file format    Chartmpstr[ -];strcpy(tmpstr,argv[1]);Char* Pext =STRRCHR(Tmpstr,'. ');STD::stringExtply ("Ply");STD::stringEXTPCD ("PCD");if(Pext) {*pext=' + ';    pext++; }STD::stringExt (pext);//If file format is not supported, exit the program    if(! (ext = = extply) | | (ext = = EXTPCD))) {STD::cout<<"file format not supported!"<<STD:: Endl;STD::cout<<"Supported file formats: *.PCD and *.ply! "<<STD:: Endl;return(-1); }//Select input mode according to file formatPCL::P OINTCLOUD&LT;PCL::P ointxyz>::P TR Cloud (NewPCL::P OINTCLOUD&LT;PCL::P ointxyz>);//Create point cloud object pointer to store input    if(ext = = extply) {if(Pcl::io::loadplyfile (argv[1], *cloud) = =-1) {Pcl_error ("Could not read ply file!\n") ;return-1; }    }Else{if(Pcl::io::loadpcdfile (argv[1], *cloud) = =-1) {Pcl_error ("Could not read PCD file!\n") ;return-1; }    }//calculation method vectorPCL::P OINTCLOUD&LT;PCL::P ointnormal>::P tr cloud_with_normals (NewPCL::P OINTCLOUD&LT;PCL::P ointnormal>);//Normal vector point cloud object pointerPCL::NORMALESTIMATION&LT;PCL::P ointxyz, pcl::normal> N;//Normal estimate objectPCL::P ointcloud<pcl::normal>::P tr normals (NewPCL::P ointcloud<pcl::normal>);//A pointer to store the estimated normalsPCL::SEARCH::KDTREE&LT;PCL::P ointxyz>::P tr Tree (NewPCL::SEARCH::KDTREE&LT;PCL::P ointxyz>);  Tree->setinputcloud (Cloud);  N.setinputcloud (Cloud);  N.setsearchmethod (tree); N.setksearch ( -); N.compute (*normals);//Calculate normals, results stored in normals    //Put the point cloud and the normals togetherPcl::concatenatefields (*cloud, *normals, *cloud_with_normals);//Create search TreePCL::SEARCH::KDTREE&LT;PCL::P ointnormal>::P tr Tree2 (NewPCL::SEARCH::KDTREE&LT;PCL::P ointnormal>); Tree2->setinputcloud (cloud_with_normals);//Create a Poisson object and set parametersPCL::P OISSON&LT;PCL::P ointnormal> pn; Pn.setconfidence (false);//Whether the size of the normal vector is used as the confidence information. If False, all normal vectors are normalized. Pn.setdegree (2);//Set parameter degree[1,5], the larger the value the finer, the longer the time. Pn.setdepth (8);//The maximum depth of the tree, solving 2^d x 2^d x 2^d cube element. Due to the eight-tree adaptive sampling density, the specified value is only the maximum depth. Pn.setisodivide (8);//depth of algorithm for extracting ISO contourPn.setmanifold (false);//Whether to add the center of gravity of the polygon when the polygon is triangulated. Set the POP flag, if set to true, to add the center of gravity when dividing the polygon into triangles, set false to not addPn.setoutputpolygons (false);//Whether to output the polygon mesh (instead of triangulation the result of moving the cube)Pn.setsamplespernode (3.0);//sets the minimum number of sample points that fall into an eight-fork tree node. No noise, [1.0-5.0], noise [15.-20.] SmoothingPn.setscale (1.25);//sets the ratio of cube diameter and sample boundary cube diameter used for refactoring. Pn.setsolverdivide (8);//Set the depth of the Gauss-seidel iterative method for solving a linear equation group    //pn.setindices ();    //Set search method and input point cloudPn.setsearchmethod (TREE2); Pn.setinputcloud (cloud_with_normals);//Create a multi-deformed mesh for storing resultsPCL::P Olygonmesh Mesh;//Perform refactoringPn.performreconstruction (mesh);//Save grid DiagramPcl::io::saveplyfile ("Result.ply", mesh);//Show result graphBoost::shared_ptr<pcl::visualization::P clvisualizer> Viewer (NewPcl::visualization::P Clvisualizer ("3D Viewer")) ; Viewer->setbackgroundcolor (0,0,0) ; Viewer->addpolygonmesh (Mesh,"My") ; Viewer->addcoordinatesystem (50.0); Viewer->initcameraparameters (); while(!viewer->wasstopped ()) {Viewer->spinonce ( -) ; Boost::this_thread::sleep (boost::p osix_time::microseconds (100000)) ; }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.
    • Enter in the command line recon_poisson.exe bunny.points.ply to execute the program. Get the result as shown.

PCL Series--Poisson reconstruction of three-dimensional reconstruction

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.