002 pcl 點雲投影

2022-05-09 09:48:12 字數 3293 閱讀 7611

1.首先包含的對應的modelcoefficients.h以及filter中向平面投影的project_inlier.h

#include #include #include #include #include
2.增加視覺化顯示的**

int user_data;

void

vieweroneoff(pcl::visualization::pclvisualizer& viewer)

void

viewerpsycho(pcl::visualization::pclvisualizer& viewer)

3.建立點雲物件指標並初始化,輸出到螢幕

/2.初始化該物件

cloud->width  = 5;//對於未組織的點雲的相當於points個數

cloud->height = 1; //對未組織的點雲指定為1

cloud->points.resize (cloud->width * cloud->height); //修剪或追加值初始化的元素

for (size_t i = 0; i < cloud->points.size (); ++i)

// 3.cerr 輸出物件放置刷屏

std::cerr << "cloud before projection: " << 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;

//投影前點

`cloud before projection:

1.28125 577.094 197.938

828.125 599.031 491.375

358.688 917.438 842.563

764.5 178.281 879.531

727.531 525.844 311.281

4.設定modelcoefficients值。在這種情況下,我們使用乙個平面模型,其中ax + by + cz + d = 0,其中a = b = d = 0,c = 1,或者換句話說,xy平面

// 4.建立乙個係數為x=y=0,z=1的平面

pcl::modelcoefficients::ptr coefficients (new pcl::modelcoefficients ());

coefficients->values.resize (4);

coefficients->values[0] = coefficients->values[1] = 0;

coefficients->values[2] = 1.0;

coefficients->values[3] = 0;

5.通過該濾波將所有的點投影到建立的平面上,並輸出結果

** 注意這裡在使用的時候再建立濾波後物件不規範,應該放在程式開始的時候**

//5.建立濾波後物件,並通過濾波投影,並顯示結果

pcl::pointcloud::ptr cloud_projected(new

pcl::pointcloud);

// 建立濾波器物件

pcl::projectinliersproj;

proj.setmodeltype (pcl::sacmodel_plane);

proj.setinputcloud (cloud);

proj.setmodelcoefficients (coefficients);

proj.filter (*cloud_projected);

//視覺化顯示

pcl::visualization::cloudviewer viewer("cloud viewer");

//showcloud函式是同步的,在此處等待直到渲染顯示為止

viewer.showcloud(cloud);

//該註冊函式在視覺化時只呼叫一次

viewer.runonvisualizationthreadonce(vieweroneoff);

//該註冊函式在渲染輸出時每次都呼叫

viewer.runonvisualizationthread(viewerpsycho);

while (!viewer.wasstopped())

std::cerr << "cloud after projection: " << std::endl;

for (size_t i = 0; i < cloud_projected->points.size (); ++i)

std::cerr << "    " << cloud_projected->points[i].x << " "

<< cloud_projected->points[i].y << " "

<< cloud_projected->points[i].z << std::endl;

return (0);

//投影後點

cloud before projection:

1.28125 577.094 197.938

828.125 599.031 491.375

358.688 917.438 842.563

764.5 178.281 879.531

727.531 525.844 311.281

cloud after projection:

1.28125 577.094 0

828.125 599.031 0

358.688 917.438 0

764.5 178.281 0

727.531 525.844 0

6.參考**

pcl官網例程

all-in_one 中的有api 以及例子,但是具體理論說明還是參考官網咖!

...\pcl-1.8.1-allinone-msvc2017-win64(1)\share\doc\pcl-1.8\tutorials\sources中 例子要比pcl入門精通要全

PCL將點向平面投影

include include include include include include int main int argc,char ar system pause return 0 這個 就是實現的是 將已知點向指定平面投影,可以計算出投影之後的點的座標 pcl projectinlier...

PCL點雲索引

點雲索引其實就是將點雲中不同點加上標籤,方便後面的分類提取。有了點雲的索引值可以方便的對點雲進行不同操作 以下舉例說明 1.儲存一點雲中某些特定的點 pcl pointcloudcloud new pcl pointcloud 輸入點雲 pcl io loadpcdfile pcd cloud pc...

pcl點雲處理

一 如何實現類似pcl pointcloud ptr和pcl pointcloud的兩個類相互轉換?include include include pcl pointcloud ptr cloudpointer new pcl pointcloud pcl pointcloudcloud cloud...