github:3d-line_detection
论文地址:
1、下载源码
打开src文件夹,将文件中.h与.cpp文件拷贝到新的vs工程中。
3、vs测试
新建VS项目,将拷贝的文件添加到项目中,如下图所示:
配置属性:作者的github中有写只需要opencv、openmp依赖,所以配置opencv属性,添加到工程中。
生成一下,此时可能会有报错,主要是opencv版本不一致,会导致部门cv中数据未定义标识符,此时需要加上opencv的头文件
#include
显示编译成功,至此就可以进行点云数据的测试了。主函数如下,其中argv[1]表示输入的txt文件,argv[2]表示输出的两种文件
void main(int argc,char**argv)
{
PointCloud<double> pointData;
readDataFromFile( argv[1], pointData );
int k = 20;
LineDetection3D detector;
std::vector<PLANE> planes;
std::vector<std::vector<cv::Point3d> > lines;
std::vector<double> ts;
detector.run( pointData, k, planes, lines, ts );
cout<<"lines number: "<<lines.size()<<endl;
cout<<"planes number: "<<planes.size()<<endl;
writeOutPlanes( argv[2], planes, detector.scale );
writeOutLines( argv[2], lines, detector.scale );
}
若想保存为pcd格式实时显示,只需要把后面两个文件txt保存为pcd,以writeOutLines为例,代码改为如下,即可保存为pcd格式文件。
pcl::PointCloud<pcl::PointXYZRGB>::Ptr get_cloud( std::vector<std::vector<cv::Point3d> > &lines, double scale)
{
// write out bounding polygon result
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_rst(new pcl::PointCloud<pcl::PointXYZRGB>);
cloud_rst->width = 1;
cloud_rst->height = lines.size();
pcl::PointXYZRGB point;
for (int p = 0; p<lines.size(); ++p)
{
point.r= rand() % 255;
point.g = rand() % 255;
point.b = rand() % 255;
cv::Point3d dev = lines[p][1] - lines[p][0];
double L = sqrt(dev.x*dev.x + dev.y*dev.y + dev.z*dev.z);
int k = L / (scale / 10);
double x = lines[p][0].x, y = lines[p][0].y, z = lines[p][0].z;
double dx = dev.x / k, dy = dev.y / k, dz = dev.z / k;
for (int j = 0; j<k; ++j)
{
x += dx;
y += dy;
z += dz;
point.x = x;
point.y = y;
point.z = z;
cloud_rst->push_back(point);
}
}
return cloud_rst;
}
后续算法会集成到QT+PCL中,共同学习,共同进步。