《PCL点云库学习&VS2010(X64)》Part 48 基于霍夫变换的点云平面检测法
来源:互联网 发布:淘宝宝贝名称规则 编辑:程序博客网 时间:2024/06/06 09:13
《PCL点云库学习&VS2010(X64)》Part 48 基于霍夫变换的点云平面检测法
参考文献:
Dorit Borrmann, Jan Elseberg, Kai Lingemann, and Andreas Nüchter. The 3D Hough Transform for Plane Detection in Point Clouds - A Review and A new Accumulator Design, Journal 3D Research, Springer, Volume 2, Number 2, March 2011.
代码:
(1)随机霍夫变换
/** * Randomized Hough Transform */int Hough::RHT() { if (!quiet) cout << "RHT" << endl; Point p1, p2, p3; double theta, phi, rho; int planeSize = 2000; unsigned int stop = (unsigned int)(allPoints->size()/100.0)*myConfigFileHough.Get_MinSizeAllPoints(); int plane = 1; long start, end; start = GetCurrentTimeInMilliSec(); int counter = 0; while( allPoints->size() > stop && planes.size() < (unsigned int)myConfigFileHough.Get_MaxPlanes() && counter < (int)myConfigFileHough.Get_TrashMax()) { unsigned int pint = (int) (((*allPoints).size())*(rand()/(RAND_MAX+1.0))); p1 = (*allPoints)[pint]; pint = (int) (((*allPoints).size())*(rand()/(RAND_MAX+1.0))); p2 = (*allPoints)[pint]; pint = (int) (((*allPoints).size())*(rand()/(RAND_MAX+1.0))); p3 = (*allPoints)[pint]; // check distance if(!distanceOK(p1, p2, p3)) continue; //cout << "Distance OK" << endl; // calculate Plane if(calculatePlane(p1, p2, p3, theta, phi, rho)) { // increment accumulator cell if(acc->accumulate(theta, phi, rho)) { end = GetCurrentTimeInMilliSec() - start; start = GetCurrentTimeInMilliSec(); if (!quiet) cout << "Time for RHT " << plane << ": " << end << endl; double * n = acc->getMax(rho, theta, phi); if (!quiet) cout << rho << " " << theta << " " << phi << endl; planeSize = deletePoints(n, rho); delete[] n; if (!quiet) cout << "Delete Points done " << plane << endl; if(planeSize < (int)myConfigFileHough.Get_MinPlaneSize()) counter++; end = GetCurrentTimeInMilliSec() - start; start = GetCurrentTimeInMilliSec(); if(!quiet) cout << "Time for Polygonization " << plane << ": " << end << endl; acc->resetAccumulator(); plane++; if(!quiet) cout << "Planes " << planes.size() << endl; } } } /* vector<Point>::iterator itr = allPoints->begin(); Point p; start = GetCurrentTimeInMilliSec(); while(itr != allPoints->end()) { p = *(itr); cout << p.x << " " << p.y << " " << p.z << endl; itr++; } */ return (int)planes.size();}
(2)标准霍夫变换方法
/** * Standard Hough Transform */void Hough::SHT() { vector<Point>::iterator itr = allPoints->begin(); Point p; long start, end; start = GetCurrentTimeInMilliSec(); while(itr != allPoints->end()) { p = *(itr); acc->accumulate(p); itr++; } end = GetCurrentTimeInMilliSec() - start; start = GetCurrentTimeInMilliSec(); if (!quiet) cout << "Time for SHT: " << end << endl; if(myConfigFileHough.Get_PeakWindow()) { acc->peakWindow(myConfigFileHough.Get_WindowSize()); } multiset<int*, maxcompare>* maxlist = acc->getMax(); multiset<int*, maxcompare>::iterator it = maxlist->begin(); int threshold = ((*it)[0] * myConfigFileHough.Get_PlaneRatio()); unsigned int stop = (int)(allPoints->size()/100.0)*myConfigFileHough.Get_MinSizeAllPoints(); while(it != maxlist->end() && stop < allPoints->size() && planes.size() < (unsigned int)myConfigFileHough.Get_MaxPlanes() && (*it)[0] > threshold) { int* tmp = (*it); double * polar = acc->getMax(tmp); deletePoints(polar, polar[3]); delete[] polar; it++; } if (!quiet) cout << "Time for Polygonization: " << end << endl; it = maxlist->begin(); for(;it != maxlist->end(); it++) { int* tmp = (*it); delete[] tmp; } delete maxlist; }
(3)概率霍夫变换
/** * Probabilistic Hough Transform */void Hough::PHT() { unsigned int stop = (int)(allPoints->size()/100.0)*myConfigFileHough.Get_MinSizeAllPoints(); bool *voted = new bool[allPoints->size()]; for(unsigned int i = 0; i < allPoints->size(); i++) { voted[i] = false; } cout << stop << endl; unsigned int i = 0; while(i < stop && planes.size() < (unsigned int)myConfigFileHough.Get_MaxPlanes()) { unsigned int pint = (int) (((*allPoints).size())*(rand()/(RAND_MAX+1.0))); if(!voted[pint]) { Point p = (*allPoints)[pint]; acc->accumulate(p); i++; voted[pint] = true; } } // List of Maxima if(myConfigFileHough.Get_PeakWindow()) { acc->peakWindow(myConfigFileHough.Get_WindowSize()); } multiset<int*, maxcompare>* maxlist = acc->getMax();// cout << "Mean " << acc->mean() << endl;// cout << "Variance " << acc->variance() << endl; multiset<int*, maxcompare>::iterator it = maxlist->begin(); int threshold = ((*it)[0] * myConfigFileHough.Get_PlaneRatio()); while(it != maxlist->end() && stop < allPoints->size() && planes.size() < (unsigned int)myConfigFileHough.Get_MaxPlanes() && (*it)[0] > threshold) { int* tmp = (*it); double * tmp2 = acc->getMax(tmp); deletePoints(tmp2, tmp2[3]); delete [] tmp2; it++; } it = maxlist->begin(); for(;it != maxlist->end(); it++) { int* tmp = (*it); delete[] tmp; } delete maxlist; delete[] voted;}
(4)渐进概率霍夫变换
/** * Progressive Probabilistic Hough Transform */void Hough::PPHT() { unsigned int stop = (int)(allPoints->size()/100.0)*myConfigFileHough.Get_MinSizeAllPoints(); while(stop < allPoints->size() && planes.size() < (unsigned int)myConfigFileHough.Get_MaxPlanes()) { bool *voted = new bool[allPoints->size()]; for(unsigned int i = 0; i < allPoints->size(); i++) { voted[i] = false; } unsigned int pint; do { pint = (int) (((*allPoints).size())*(rand()/(RAND_MAX+1.0))); Point p = (*allPoints)[pint]; if(!voted[pint]) { double * angles = acc->accumulateRet(p); if(angles[0] > -0.0001) { double * n = polar2normal(angles[1], angles[2]); deletePoints(n, angles[0]); acc->resetAccumulator(); delete [] n; } else { voted[pint] = true; } delete [] angles; } } while(!voted[pint]); delete[] voted; }}
(5)自适应霍夫变换
/** * Adaptive Probabilistic Hough Transform */void Hough::APHT() { int max = 0; int maxpos = 0; vector<int*> mergelist = vector<int*>(); int stability[20] = {0}; do { //randomly select points and perform HT for them vector<int*> altlist = mergelist; mergelist = vector<int*>(); multiset<int*,valuecompare> maxlist = multiset<int*,valuecompare>(); for(int i = 0; i < 10; i++) { unsigned int pint = (int) (((*allPoints).size())*(rand()/(RAND_MAX+1.0))); Point p = (*allPoints)[pint]; int * max = acc->accumulateAPHT(p); // store the maximum cell touched by the HT maxlist.insert(max); } // merge active with previous list multiset<int*,valuecompare>::iterator mi = maxlist.begin(); vector<int*>::iterator ai = altlist.begin(); int i = 0; while(i < 20) { bool mi_oder_ai = false; if(ai == altlist.end()) { if(mi == maxlist.end()) { break; } else { mi_oder_ai = true; } } else if(mi == maxlist.end()) { mi_oder_ai = false; } else if((*mi)[0] <= (*ai[0])) { mi_oder_ai = false; } else { mi_oder_ai = true; } int *tmp; if(mi_oder_ai) { tmp = (*mi); mi++; } else { tmp = (*ai); ai++; } bool insert = true; for(vector<int*>::iterator it = mergelist.begin(); it != mergelist.end(); it++) { if(myConfigFileHough.Get_AccumulatorType() != 2) { if( sqrt((float) ((*it)[3] - (tmp[3])) * ((*it)[3] - (tmp[3])) + ((*it)[1] - (tmp[1])) * ((*it)[1] - (tmp[1])) + ((*it)[2] - (tmp[2])) * ((*it)[2] - (tmp[2])) ) < 3.0f) { insert = false; break; } } else { if( sqrt((float) ((*it)[4] - (tmp[4])) * ((*it)[4] - (tmp[4])) + ((*it)[1] - (tmp[1])) * ((*it)[1] - (tmp[1])) + ((*it)[2] - (tmp[2])) * ((*it)[2] - (tmp[2])) + ((*it)[3] - (tmp[3])) * ((*it)[3] - (tmp[3])) ) < 3.0f) { insert = false; break; } } } if(insert) { mergelist.push_back(tmp); i++; } } // compare lists, calculate stability i = 0; for(unsigned int i = 1; i < altlist.size(); i++) { for(unsigned int j = 0; j < i; j++) { int * tmp1 = mergelist[j]; bool treffer = false; for(unsigned int k = 0; k < i; k++) { int * tmp2 = altlist[k]; if(myConfigFileHough.Get_AccumulatorType() != 2) { if( sqrt((float) ((tmp2)[3] - (tmp1[3])) * ((tmp2)[3] - (tmp1[3])) + ((tmp2)[1] - (tmp1[1])) * ((tmp2)[1] - (tmp1[1])) + ((tmp2)[2] - (tmp1[2])) * ((tmp2)[2] - (tmp1[2])) ) < 3.0f) { treffer = true; break; } } else { if( sqrt((float) ((tmp2)[4] - (tmp1[4])) * ((tmp2)[4] - (tmp1[4])) + ((tmp2)[1] - (tmp1[1])) * ((tmp2)[1] - (tmp1[1])) + ((tmp2)[2] - (tmp1[2])) * ((tmp2)[2] - (tmp1[2])) + ((tmp2)[3] - (tmp1[3])) * ((tmp2)[3] - (tmp1[3])) ) < 3.0f) { treffer = true; break; } } } if(!treffer) { stability[i-1] = -1; break; } } stability[i-1]++; } for(int i = mergelist.size(); i < 20; i++) { stability[i] = 0; } // determine stability count, // a set of n entries is considered to be stable, if all planes in the set // are the maximal entries of the mergelist in this iteration and have also // been the maximal entries in the previous iteration (the order in the set // does not count). The stability count for a number n is the number of // iterations for which the set of size n has been stable. // The maximum stability count is the stability count for the size n, that // is the maximum of all stability counts. max = 0; maxpos = 0; for(int i = 0; i < 20; i++) { if(stability[i] >= max) { max = stability[i]; maxpos = i; } } // repeat until maximum stability count exceeds a threshold } while(max < (int)myConfigFileHough.Get_AccumulatorMax() && stability[myConfigFileHough.Get_MaxPlanes()] < myConfigFileHough.Get_AccumulatorMax() * myConfigFileHough.Get_PlaneRatio() ); if(stability[myConfigFileHough.Get_MaxPlanes()] >= myConfigFileHough.Get_AccumulatorMax() * myConfigFileHough.Get_PlaneRatio()) { maxpos = myConfigFileHough.Get_MaxPlanes(); } for(int i = 0; i <= maxpos; i++) { double * n = acc->getMax(mergelist[i]); deletePoints(n, n[3]); delete[] n; }}
阅读全文
0 0
- 《PCL点云库学习&VS2010(X64)》Part 48 基于霍夫变换的点云平面检测法
- 《PCL点云库学习&VS2010(X64)》Part 32 计算点云中点的索引
- 《PCL点云库学习&VS2010(X64)》Part 47 鼠标选取点云坐标的计算原理
- 《PCL点云库学习&VS2010(X64)》Part 25 PCL点云操作函数汇集
- 《PCL点云库学习&VS2010(X64)》Part 22 激光雷达点云数据处理相关算法库收集
- 《PCL点云库学习&VS2010(X64)》Part 45 点云压缩算法—扫描线(DouglasPeuckerAlgorithm)
- 《PCL点云库学习&VS2010(X64)》Part 46 点云分类—画刷分类
- 《PCL点云库学习&VS2010(X64)》Part 40 三角网格碰撞检测
- 《PCL点云库学习&VS2010(X64)》Part 39 批处理命令设置PCL的环境变量
- 《PCL点云库学习&VS2010(X64)》Part 14 PCL1.72(VTK6.2.0)点云分割(Point Cloud Segmentation)
- 《PCL点云库学习&VS2010(X64)》Part 18 PCL1.72(VTK6.2.0)编译CloudCompare注意点
- 《PCL点云库学习&VS2010(X64)》Part 5 VTK6.2+VS2013+Qt5.5 测试VTK基于VS2013的Qt程序
- 《PCL点云库学习&VS2010(X64)》Part 1 Installation of PCL in VS2010(x64)
- 《PCL点云库学习&VS2010(X64)》Part 4 MFC+VTK+VS2010 测试VTK的MFC对话框程序
- 《PCL点云库学习&VS2010(X64)》Part 28 BoundingBox&addArray
- 《PCL点云库学习&VS2010(X64)》Part 42 OCtreeViewer
- 《PCL点云库学习&VS2010(X64)》Part 31 pcl::PointCloud::Ptr和pcl::PointCloud相互转换
- 《PCL点云库学习&VS2010(X64)》Part 41 图形学领域的关键算法及源码链接
- java包装类默认值==比较空指针异常详解
- 深入浅出mysql-sql基础
- 数据结构实验之排序四:寻找大富翁
- 防止SQL注入:永远不要信任外界输入的数据,特别是来自于客户端的,包括选择框、表单隐藏域和 cookie
- Rhyme/Hibernate getCurrentSession()与openSession()的区别
- 《PCL点云库学习&VS2010(X64)》Part 48 基于霍夫变换的点云平面检测法
- spring boot guava cache 缓存学习
- 微信小程序商品筛选,侧方弹出动画选择页面
- js实现星星评分功能的实现,并获取评分多少的功能(附源码)
- 学习矢量量化-LVQ
- Scala中for循环逆序遍历数组
- Hcdp认证培训是什么?
- 生成对抗网络(GAN)的理论与应用完整入门介绍
- 考研,加油,祝福你们