[英]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.