PCL Series--Planar model segmentation

Source: Internet
Author: User
Tags rand

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 PCL series--Plane model segmentation Description

Code Download Code

#include <iostream> #include <pcl/ModelCoefficients.h>//model factor #include <pcl/io/pcd_io.h>  Input/Output #include <pcl/point_types.h>//Point cloud (type) #include <pcl/sample_consensus/method_types.h> Random sample Consistency algorithm method type #include <pcl/sample_consensus/model_types.h>//random sample Conformance algorithm model type #include <pcl/segmentation /sac_segmentation.h>//Random Sample Consistency algorithm segmentation method int main (int argc, char** argv) {PCL::P OINTCLOUD&LT;PCL::P ointxyz> Cloud ;
  Create a point cloud object for storing point cloud data//Fill point cloud data cloud.width = 15;
  Cloud.height = 1;

    Cloud.points.resize (Cloud.width * cloud.height);  Generate random data for (size_t i = 0; i < cloud.points.size (); ++i) {cloud.points[i].x = 1024x768 * RAND ()/(Rand_max +
    1.0f);
    CLOUD.POINTS[I].Y = 1024x768 * RAND ()/(Rand_max + 1.0f);
  CLOUD.POINTS[I].Z = 1.0;
    }//Set several outsider points cloud.points[0].z = 2.0;
    Cloud.points[3].z =-2.0;
    CLOUD.POINTS[6].Z = 4.0; Display point cloud number and coordinate information Std::cerr << "points cloud DATA: "<< cloud.points.size () <<" points "<< Std::endl;  for (size_t i = 0; i < cloud.points.size (); ++i) Std::cerr << "" << cloud.points[i].x << "<< cloud.points[i].y <<" "<< cloud.poin

    Ts[i].z << Std::endl; Pcl::modelcoefficients::P TR coefficients (new pcl::modelcoefficients); Coefficient of the model that stores the output PCL::P ointindices::P tr inliers (new PCL::P ointindices);
    Store inside points, use points//Create segmented Objects PCL::SACSEGMENTATION&LT;PCL::P ointxyz> seg;
    Optional setting seg.setoptimizecoefficients (TRUE); Seg.setmodeltype (Pcl::sacmodel_plane) must be set;      Set the model type, detect plane Seg.setmethodtype (PCL::SAC_RANSAC);
  Set method "Cluster or random sample consistency" seg.setdistancethreshold (0.01);
  Seg.setinputcloud (cloud.makeshared ());    Seg.segment (*inliers, *coefficients); Split operation if (inliers->indices.size () = = 0)//depending on the number of dots, determine if the success {Pcl_error ("Could not estimate a planar modelFor the given dataset. ");
  Return (-1); 
                        }//Display the model's coefficients std::cerr << "model coefficients:" << coefficients->values[0] << "" <<coefficients->values[1] << "<<coefficients->values[2" &lt
    ;< "<<coefficients->values[3" <<std::endl;
    Displays the interior points used during the estimation of the plane model Std::cerr << "Model inliers:" << inliers->indices.size () << Std::endl;  for (size_t i = 0; i < inliers->indices.size (); ++i) Std::cerr << Inliers->indices[i] << "<<cloud.points[inliers->indices[i]].x <<" "<<cloud.points[i Nliers->indices[i]].y << "<<cloud.points[inliers->indices[i]].z <& Lt
    Std::endl;
return (0);
 }
Run Results

Reference

"Point Cloud Library PCL Learning Tutorial" Chapter 14

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.