本文由CSDN点云侠原创,CloudCompare——统计滤波,爬虫自重。如果你不是在点云侠的博客中看到该文章,那么此处便是不要脸的爬虫。
1.统计滤波
算法原理见:PCL 统计滤波器。
2.软件实现
参数设置
文章来源:https://www.toymoban.com/news/detail-671115.html
3.完整操作
文章来源地址https://www.toymoban.com/news/detail-671115.html
4.算法源码
ReferenceCloud* CloudSamplingTools::sorFilter( GenericIndexedCloudPersist* inputCloud,
int knn/*=6*/,
double nSigma/*=1.0*/,
DgmOctree* inputOctree/*=0*/,
GenericProgressCallback* progressCb/*=0*/)
{
if (!inputCloud || knn <= 0 || inputCloud->size() <= static_cast<unsigned>(knn))
{
//invalid input
assert(false);
return nullptr;
}
DgmOctree* octree = inputOctree;
if (!octree)
{
//compute the octree if necessary
octree = new DgmOctree(inputCloud);
if (octree->build(progressCb) < 1)
{
delete octree;
return nullptr;
}
}
//output
ReferenceCloud* filteredCloud = nullptr;
for (unsigned step = 0; step < 1; ++step) //fake loop for easy break
{
unsigned pointCount = inputCloud->size();
std::vector<PointCoordinateType> meanDistances;
try
{
meanDistances.resize(pointCount, 0);
}
catch (const std::bad_alloc&)
{
//not enough memory
break;
}
double avgDist = 0;
double stdDev = 0;
//1st step: compute the average distance to the neighbors
{
//additional parameters
void* additionalParameters[] = {reinterpret_cast<void*>(&knn),
reinterpret_cast<void*>(&meanDistances)
};
unsigned char octreeLevel = octree->findBestLevelForAGivenPopulationPerCell(knn);
if (octree->executeFunctionForAllCellsAtLevel( octreeLevel,
&applySORFilterAtLevel,
additionalParameters,
true,
progressCb,
"SOR filter") == 0)
{
//something went wrong
break;
}
//deduce the average distance and std. dev.
double sumDist = 0;
double sumSquareDist = 0;
for (unsigned i = 0; i < pointCount; ++i)
{
sumDist += meanDistances[i];
sumSquareDist += meanDistances[i] * meanDistances[i];
}
avgDist = sumDist / pointCount;
stdDev = sqrt(std::abs(sumSquareDist / pointCount - avgDist*avgDist));
}
//2nd step: remove the farthest points
{
//deduce the max distance
double maxDist = avgDist + nSigma * stdDev;
filteredCloud = new ReferenceCloud(inputCloud);
if (!filteredCloud->reserve(pointCount))
{
//not enough memory
delete filteredCloud;
filteredCloud = nullptr;
break;
}
for (unsigned i = 0; i < pointCount; ++i)
{
if (meanDistances[i] <= maxDist)
{
filteredCloud->addPointIndex(i);
}
}
filteredCloud->resize(filteredCloud->size());
}
}
if (!inputOctree)
{
delete octree;
octree = nullptr;
}
return filteredCloud;
}
5.相关代码
- PCL 统计滤波器
- PCL 统计滤波(C++详细过程版)
- Open3D(C++) 统计滤波
- Open3D 统计滤波器
- matlab 点云统计滤波
到了这里,关于CloudCompare——统计滤波的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!