1

我有一个在所有 3 个维度上都具有广泛范围的点云数据。我已经使用 pcl::ConditionalRemoval::filter() 在 -20 >= x >= 20、-20 >= y >= 20 和 -2 >= z >= 2 范围内对其进行过滤。现在我想要 min 和每个维度的最大值,所以我在网上搜索了 nay PCL 函数。我得到pcl::getMinMax3D。我使用它并验证我也在云数据中手动搜索。代码如下:

float xmin = 10000, xmax=-10000;

cout << "Manual Search Result:"<<endl;

for(unsigned int i = 0; i < filtered_data->size(); i++)
{
    if(filtered_data->at(i)._PointXYZ::x > xmax)
        xmax = filtered_data->at(i)._PointXYZ::x;
    if(filtered_data->at(i)._PointXYZ::x < xmin)
        xmin = filtered_data->at(i)._PointXYZ::x;
}

cout << "Xmin: " << xmin << "\t\tXmax: " << xmax << endl;

float ymin = 10000, ymax=-10000;

for(unsigned int i = 0; i < filtered_data->size(); i++)
{
    if(filtered_data->at(i)._PointXYZ::y > ymax)
        ymax = filtered_data->at(i)._PointXYZ::y;
    if(filtered_data->at(i)._PointXYZ::y < ymin)
        ymin = filtered_data->at(i)._PointXYZ::y;
}
cout << "Ymin: " << ymin << "\t\tYmax: " << ymax << endl;

float zmin = 10000, zmax=-10000;

for(unsigned int i = 0; i < filtered_data->size(); i++)
{
    if(filtered_data->at(i)._PointXYZ::z > zmax)
        zmax = filtered_data->at(i)._PointXYZ::z;
    if(filtered_data->at(i)._PointXYZ::z < zmin)
        zmin = filtered_data->at(i)._PointXYZ::z;
}
cout << "Zmin: " << zmin << "\t\tZmax: " << zmax << endl;

pcl::PointXYZ minPt, maxPt;
pcl::getMinMax3D (*filtered_data, minPt, maxPt);

cout << "getMinMax3D Search Result:"<<endl;

std::cout << "Min x: " << minPt.x << "\t\tMax x: " << maxPt.x << std::endl;
std::cout << "Min y: " << minPt.y << "\t\tMax y: " << maxPt.y << std::endl;
std::cout << "Min z: " << minPt.z << "\t\tMax z: " << maxPt.z << std::endl;

我得到的输出是:

Manual Search Result:
Xmin: -19.992       Xmax: 19.915
Ymin: -19.75        Ymax: 19.982
Zmin: -1.999        Zmax: 1.059
getMinMax3D Search Result: 
Min x: -3.895       Max x: 3.967
Min y: -4.238       Max y: 4.291
Min z: -1.887       Max z: 0

我对 getMinMax3D() 的使用理解有误吗?

4

1 回答 1

0

如果输入cloud有 NAN 点,请确保设置cloud.is_densefalse,否则该函数pcl::getMinMax3D不会检查 NaN。

这是来自https://pointclouds.org/documentation/common_2include_2pcl_2common_2impl_2common_8hpp_source.html的原始实现


 template <typename PointT> inline void
 pcl::getPointsInBox (const pcl::PointCloud<PointT> &cloud, 
                      Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
                      Indices &indices)
 {
   indices.resize (cloud.size ());
   int l = 0;
  
   // If the data is dense, we don't need to check for NaN
   if (cloud.is_dense)
   {
     for (std::size_t i = 0; i < cloud.size (); ++i)
     {
       // Check if the point is inside bounds
       if (cloud[i].x < min_pt[0] || cloud[i].y < min_pt[1] || cloud[i].z < min_pt[2])
         continue;
       if (cloud[i].x > max_pt[0] || cloud[i].y > max_pt[1] || cloud[i].z > max_pt[2])
         continue;
       indices[l++] = int (i);
     }
   }
   // NaN or Inf values could exist => check for them
   else
   {
     for (std::size_t i = 0; i < cloud.size (); ++i)
     {
       // Check if the point is invalid
       if (!std::isfinite (cloud[i].x) || 
           !std::isfinite (cloud[i].y) || 
           !std::isfinite (cloud[i].z))
         continue;
       // Check if the point is inside bounds
       if (cloud[i].x < min_pt[0] || cloud[i].y < min_pt[1] || cloud[i].z < min_pt[2])
         continue;
       if (cloud[i].x > max_pt[0] || cloud[i].y > max_pt[1] || cloud[i].z > max_pt[2])
         continue;
       indices[l++] = int (i);
     }
   }
   indices.resize (l);
 }

于 2021-08-23T12:02:33.020 回答