PCL Point cloud file generation and Reading

Source: Internet
Author: User
Tags rand
Summary

The PCL creates a file-PCD for describing the set of spatial points. For a brief introduction to PCD, see here-http://pointclouds.org/documentation/tutorials/pcd_file_format.php

Today is the simplest thing to do-the production and reading of PCD files.

Environment: Win7 64bit VS2010 PCL1.7

PCL Compile reference here-Window7 manually compile the latest version of the PCL library


PCD file Generation

The official website recommended is to use CMake to manage the project, in Windows, we can cmakegui to generate VS2010 project, and then import. This eliminates the various additions to the Lib in VS, the head file of the bitter ^^

First create the main program Pcd_write.cpp , just find a notepad to write it, the code is as follows:

[CPP]  View plain  copy #include  <iostream>   #include  <pcl/io/io.h>    #include  <pcl/io/pcd_io.h>   #include  <pcl/point_types.h>   # include <pcl/visualization/cloud_viewer.h>   using namespace std;         int main  (int argc, char** argv)    {   &NBSP;&NBSP;PCL::P ointcloud<pcl::P ointxyz> cloud;     // Fill in  the cloud data     cloud.width    = 5;      cloud.height   = 1;     cloud.is_dense = false;      cloud.points.resize  (cloud.width * cloud.height);        for  (size_t i = 0; i < cloud.points.size  ();  ++i)  &nbsP   {       cloud.points[i].x = 1024 * rand  ()  /  (rand_max + 1.0f);       cloud.points[i].y =  1024 * rand  ()  /  (rand_max + 1.0f);        cloud.points[i].z = 1024 * rand  ()  /  (rand_max + 1.0f);      }        pcl::io::savePCDFileASCII  ("TEST_PCD.PCD",  Cloud);     std::cerr <<  "saved "  << cloud.points.size   ()  <<  "&NBSP;DATA&NBSP;POINTS&NBSP;TO&NBSP;TEST_PCD.PCD."  << std::endl;        for  (size_t i = 0;  i < cloud.points.size  ();  ++i)        std::cerr < <  "    "  << cloud.points[i].x <<  " "  << cloud.points[i].y <<   " "  << cloud.points[i].z << std::endl;        getchar ();     return  (0);  }  
Re-create CMakeLists.txt

[plain] view plain copy cmake_minimum_required (VERSION 2.6 fatal_error) project (my_grand_project) Find_pack Age (PCL 1.3 REQUIRED components common IO) include_directories (${pcl_include_dirs}) link_directories (${pcl_library_di RS}) add_definitions (${pcl_definitions}) add_executable (Pcd_write_test pcd_write.cpp) target_link_libraries (pcd_ Write_test ${pcl_common_libraries} ${pcl_io_libraries})
Create a build folder under the project directory, then open Cmake-gui, CMakeList.txt, configure->generate. If the environment is configured properly, the result is like this:



If the error, the basic is that your environment is not configured well, check whether the loaded things are installed, environment variables are set.


Success time in the build folder under the corresponding VS2010 project, the direct double hit Open My_grand_project.sln



After import, on Cloud_view , right-click->set as StartUp Project, as shown in the following illustration:



Run directly, the effect is as follows:


A test_pcd.pcd point cloud File is generated in the project catalog.


reading of point cloud files

The routine is just like the one above, just stick to the code.

Cloud_viewer.cpp

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.