簡體   English   中英

如何將點雲投影到地平面上並將其轉換為點雲庫中的二維圖像(OpenCV Mat)?

[英]How to project point cloud onto the ground plane and transfer it into an 2D image (OpenCV Mat) in Point Cloud Library?

我想分割地面上的石頭並像這樣計算石頭的面積:

在此處輸入圖片說明

在此處輸入圖片說明

寫了2年OpenCV,發現只用OpenCV RGB圖片很難分割石頭,所以我用kinect fusion掃描地面,得到一個點雲,石頭比地面高。
我使用點雲庫來分割地平面(綠色),如下所示:

在此處輸入圖片說明

現在我試圖將其余點投影到地平面上並獲得 OpenCV Mat 格式的 2D 圖像(原始點的高度成為地面 2D 圖像中投影點的值),結果是灰色墊子圖片。 但這對我來說很困難,你能給我一些建議嗎?

如果我成功獲得新的灰色墊子,那么我可以對其進行分割,這對我來說很容易。

順便說一句,有沒有點雲查看器可以看到點的(x,y,z)坐標?

這是我的主要代碼:

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);

pcl::io::loadPLYFile ("MeshedReconstruction.ply", *cloud);

pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers_groud (new pcl::PointIndices);
// Create the segmentation object
pcl::SACSegmentation<pcl::PointXYZ> seg;
// Optional
seg.setOptimizeCoefficients (true);
// Mandatory
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setDistanceThreshold (0.01);//1cm

seg.setInputCloud (cloud);
seg.segment (*inliers_groud, *coefficients);

if (inliers_groud->indices.size () == 0)
{
    PCL_ERROR ("Could not estimate a planar model for the given dataset.");
    return (-1);
}

std::cerr << "Model coefficients: " << coefficients->values[0] << " " 
    << coefficients->values[1] << " "
    << coefficients->values[2] << " " 
    << coefficients->values[3] << std::endl;

std::cerr << "Model inliers_groud: " << inliers_groud->indices.size () << std::endl;

// Create the filtering object
pcl::ExtractIndices<pcl::PointXYZ> extract;
extract.setInputCloud (cloud);
extract.setIndices (inliers_groud);
extract.setNegative(false);

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_groud (new pcl::PointCloud<pcl::PointXYZ>);

extract.filter (*cloud_groud);//get the ground plane

std::cerr << "Ground cloud after filtering: " << std::endl;
std::cerr << *cloud_groud << std::endl;

pcl::PCDWriter writer;
writer.write<pcl::PointXYZ> ("samp11-utm_ground.pcd", *cloud_groud, false);

我的答案:

看看這個 PCL api: http : //docs.pointclouds.org/1.7.2/a02405.html#ga4375e99ec2ae368eec9379f506568611

我成功解決了這個問題!

結果很好(紫色平面是原始地面,綠色平面是轉換的地面平面,即XOY平面):在此處輸入圖片說明

現在如果 pcl::PointXYZ 是 (x0, y0, z0),那么 Mat (x0,y0) 上的點是 z0。 結果:在此處輸入圖片說明

當您談論將某些東西投影到地平面時,通常您需要投影矩陣 (K [R|t])。 在你的情況下,如果我理解正確,你想做一個正交投影,這意味着你想松開 Z ​​坐標: http : //en.wikipedia.org/wiki/Orthographic_projection

現在,你的情況等式將是這樣的

z_max = max z(Pts[x,y,z])
im[x,y] = z_max

請注意,您需要在雲中的給定 xy 點中搜索最大高度 (Z)。

我希望這可以幫助你...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM