Menü Kapat

PCL Kütüphanesi Octree Kodunun Çalıştırılması (Run PCL Octree Code)

Daha önceden anlatıldığı gibi PCL kütüphanesi kurulduktan sonra bir octree kodunun çalıştırılması için aşağıdaki işlemler yapılmalıdır.

  • Herhangibir klasörde bir diziinoluşturarak bu dizine gidiyoruz.
  • Burada build adında bir klasörü aşağıdaki gibi oluşturuyoruz.
mkdir build

 

  • Daha sonra oluşturulan klasörün içine cloud_viewer.cpp CMakeLists.txt ve Bu linkteki örnek pcd uzantılı pcl dataseti indirilerek atıyoruz.

CMakeLists.txt’nin içeriği

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(cloud_viewer)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (cloud_viewer cloud_viewer.cpp)
target_link_libraries (cloud_viewer ${PCL_LIBRARIES})

cloud_viewer.cpp dosyasının içeriği

#include <pcl/visualization/cloud_viewer.h>
#include
#include <pcl/io/io.h>
#include <span class="pl-k"><</span>pcl<span class="pl-k">/</span>io<span class="pl-k">/</span>pcd_io<span class="pl-k">.</span>h<span class="pl-k">></span>
<span class="pl-c">/////////////////////</span>
#include <span class="pl-k"><</span>pcl<span class="pl-k">/</span>point_cloud<span class="pl-k">.</span>h<span class="pl-k">></span>
#include <span class="pl-k"><</span>pcl<span class="pl-k">/</span>point_types<span class="pl-k">.</span>h<span class="pl-k">></span>
#include <span class="pl-k"><</span>pcl<span class="pl-k">/</span>io<span class="pl-k">/</span>openni_grabber<span class="pl-k">.</span>h<span class="pl-k">></span>
#include <span class="pl-k"><</span>pcl<span class="pl-k">/</span>visualization<span class="pl-k">/</span>cloud_viewer<span class="pl-k">.</span>h<span class="pl-k">></span>

#include <span class="pl-k"><</span>pcl<span class="pl-k">/</span>compression<span class="pl-k">/</span>octree_pointcloud_compression<span class="pl-k">.</span>h<span class="pl-k">></span>
#include <span class="pl-k"><</span>stdio<span class="pl-k">.</span>h<span class="pl-k">></span>
#include <span class="pl-k"><</span>sstream<span class="pl-k">></span>
#include <span class="pl-k"><</span>stdlib<span class="pl-k">.</span>h<span class="pl-k">></span>

#include <span class="pl-k"><</span>pcl<span class="pl-k">/</span>octree<span class="pl-k">/</span>octree<span class="pl-k">.</span>h<span class="pl-k">></span>
#include <span class="pl-k"><</span>vector<span class="pl-k">></span>
#include <span class="pl-k"><</span>ctime<span class="pl-k">></span>

using namespace std;
<span class="pl-k">int</span> user_data;

<span class="pl-k">void</span> viewerOneOff (pcl<span class="pl-k">::</span>visualization<span class="pl-k">::</span><span class="pl-smi">PCLVisualizer</span><span class="pl-k">&</span> viewer)
{
    viewer<span class="pl-k">.</span>setBackgroundColor (<span class="pl-c1">1.0</span>, <span class="pl-c1">0.5</span>, <span class="pl-c1">1.0</span>);
    pcl<span class="pl-k">::</span><span class="pl-smi">PointXYZ</span> o;
    o<span class="pl-k">.</span>x <span class="pl-k">=</span> <span class="pl-c1">1.0</span>;
    o<span class="pl-k">.</span>y <span class="pl-k">=</span> <span class="pl-c1">0</span>;
    o<span class="pl-k">.</span>z <span class="pl-k">=</span> <span class="pl-c1">0</span>;
    viewer<span class="pl-k">.</span>addSphere (o, <span class="pl-c1">0.25</span>, <span class="pl-s"><span class="pl-pds">"</span>sphere<span class="pl-pds">"</span></span>, <span class="pl-c1">0</span>);
    std<span class="pl-k">::</span>cout <span class="pl-k"><<</span> <span class="pl-s"><span class="pl-pds">"</span>i only run once<span class="pl-pds">"</span></span> <span class="pl-k"><<</span> std<span class="pl-k">::</span>endl;

}

<span class="pl-k">void</span> viewerPsycho (pcl<span class="pl-k">::</span>visualization<span class="pl-k">::</span><span class="pl-smi">PCLVisualizer</span><span class="pl-k">&</span> viewer)
{
    <span class="pl-k">static</span> unsigned count <span class="pl-k">=</span> <span class="pl-c1">0</span>;
    std<span class="pl-k">::</span>stringstream ss;
    ss <span class="pl-k"><<</span> <span class="pl-s"><span class="pl-pds">"</span>Once per viewer loop: <span class="pl-pds">"</span></span> <span class="pl-k"><<</span> count<span class="pl-k">++</span>;
    viewer<span class="pl-k">.</span>removeShape (<span class="pl-s"><span class="pl-pds">"</span>text<span class="pl-pds">"</span></span>, <span class="pl-c1">0</span>);
    viewer<span class="pl-k">.</span>addText (ss<span class="pl-k">.</span>str(), <span class="pl-c1">200</span>, <span class="pl-c1">300</span>, <span class="pl-s"><span class="pl-pds">"</span>text<span class="pl-pds">"</span></span>, <span class="pl-c1">0</span>);

    <span class="pl-c">//FIXME: possible race condition here:</span>
    user_data<span class="pl-k">++</span>;
}

<span class="pl-k">int</span>
main ()
{

    bool showStatistics <span class="pl-k">=</span> <span class="pl-c1">true</span>;
    pcl<span class="pl-k">::</span>io<span class="pl-k">::</span><span class="pl-k">OctreePointCloudCompression<pcl:</span><span class="pl-k">:</span><span class="pl-smi">PointXYZRGBA</span><span class="pl-k">></span><span class="pl-k">*</span> <span class="pl-smi">PointCloudEncoder</span>;
    pcl<span class="pl-k">::</span>io<span class="pl-k">::</span><span class="pl-k">OctreePointCloudCompression<pcl:</span><span class="pl-k">:</span><span class="pl-smi">PointXYZRGBA</span><span class="pl-k">></span><span class="pl-k">*</span> <span class="pl-smi">PointCloudDecoder</span>;

    pcl<span class="pl-k">::</span>io<span class="pl-k">::</span>compression_Profiles_e compressionProfile <span class="pl-k">=</span> pcl<span class="pl-k">::</span>io<span class="pl-k">::</span><span class="pl-c1">LOW_RES_OFFLINE_COMPRESSION_WITH_COLOR</span>;

    <span class="pl-c">// instantiate point cloud compression for encoding and decoding</span>
    <span class="pl-smi">PointCloudEncoder</span> <span class="pl-k">=</span> <span class="pl-k">new</span> pcl::io::<span class="pl-k">OctreePointCloudCompression<pcl:</span>:<span class="pl-smi">PointXYZRGBA</span>> (compressionProfile, showStatistics);
    <span class="pl-smi">PointCloudDecoder</span> <span class="pl-k">=</span> <span class="pl-k">new</span> pcl::io::<span class="pl-k">OctreePointCloudCompression<pcl:</span>:<span class="pl-smi">PointXYZRGBA</span>> ();

    pcl<span class="pl-k">::</span><span class="pl-k">PointCloud<pcl:</span><span class="pl-k">:</span><span class="pl-smi">PointXYZRGBA</span><span class="pl-k">></span><span class="pl-k">::</span><span class="pl-smi">Ptr</span> cloud (<span class="pl-k">new</span> pcl::PointCloud<pcl::PointXYZRGBA>);
    pcl<span class="pl-k">::</span>io<span class="pl-k">::</span>loadPCDFile (<span class="pl-s"><span class="pl-pds">"</span>/home/yapbenzet/Documents/Untitled Folder/samp23-utm-ground.pcd<span class="pl-pds">"</span></span>, <span class="pl-k">*</span>cloud);

    pcl<span class="pl-k">::</span>visualization<span class="pl-k">::</span><span class="pl-smi">CloudViewer</span> viewer(<span class="pl-s"><span class="pl-pds">"</span>Cloud Viewer<span class="pl-pds">"</span></span>);

      std<span class="pl-k">::</span>stringstream compressedData;

      pcl<span class="pl-k">::</span><span class="pl-k">PointCloud<pcl:</span><span class="pl-k">:</span><span class="pl-smi">PointXYZRGBA</span><span class="pl-k">></span><span class="pl-k">::</span><span class="pl-smi">Ptr</span> cloudOut (<span class="pl-k">new</span> pcl::<span class="pl-k">PointCloud<pcl:</span>:<span class="pl-smi">PointXYZRGBA</span>> ());

<span class="pl-c">// datayı sıkıştırmak için kullanılıyor.</span>
      <span class="pl-smi">PointCloudEncoder</span><span class="pl-k">-</span><span class="pl-k">></span>encodePointCloud (cloud, compressedData);

      <span class="pl-smi">PointCloudDecoder</span><span class="pl-k">-</span><span class="pl-k">></span>decodePointCloud (compressedData, cloudOut);

<span class="pl-c">// Octree için aşağıdaki yorum satırlarını aktif edip yukarıdaki 2 satırı yorum satırı yapmalıyız.</span>

 <span class="pl-c">/*float resolution = 128.0f;</span>

<span class="pl-c"> 	 pcl::octree::OctreePointCloudSearch<pcl::PointXYZRGBA> octree (resolution);</span>

<span class="pl-c"> 	 octree.setInputCloud (cloud);</span>
<span class="pl-c"> 	 octree.addPointsFromInputCloud ();*/</span>

viewer<span class="pl-k">.</span>showCloud (cloud);

    viewer<span class="pl-k">.</span>runOnVisualizationThreadOnce (viewerOneOff);

    viewer<span class="pl-k">.</span>runOnVisualizationThread (viewerPsycho);
    <span class="pl-k">while</span> (<span class="pl-k">!</span>viewer<span class="pl-k">.</span>wasStopped ())
    {
    	user_data<span class="pl-k">++</span>;
    }
    <span class="pl-k">return</span> <span class="pl-c1">0</span>;
}

cmake ve make işlemlerini yapıyoruz.

cmake ..
make

Son olarak oluşturulan görünüm dosyasını çalıştırıyoruz ve aşağıdaki gibi bir çıktı elde ediyoruz.

./cloud_viewer
octree

Bir yorum yazınız. Yorumlarınız bizim için değerlidir.