当前位置:网站首页>Circle detection and line detection of PCL
Circle detection and line detection of PCL
2022-07-25 22:57:00 【kissgoodbye2012】
One 、 Circle detection
// Search all circles , Know that no eligible circle can be found , Record the center and radius of the circle
int index=0;
while(1)
{
pcl::visualization::PCLVisualizer viewer2("Visualization of original and target point cloud");
viewer2.setBackgroundColor(255,255,255);
pcl::PointCloud<pcl::PointXYZ>::Ptr Circle2D(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr tempRemain(new pcl::PointCloud<pcl::PointXYZ>);
pcl::SampleConsensusModelCircle2D<pcl::PointXYZ>::Ptr model_circle2D(new pcl::SampleConsensusModelCircle2D<pcl::PointXYZ>(Src_Cloud_Planar));
std::vector<int> inliers;
pcl::RandomSampleConsensus<pcl::PointXYZ> ransac(model_circle2D);
ransac.setDistanceThreshold(0.001);
ransac.computeModel();
ransac.getInliers(inliers);
qDebug()<<" Number of point clouds :"<<inliers.size();
// If you can't find a circle , sign out
if(inliers.size()==0)
{
break;
}
pcl::IndicesPtr tempinliers(new std::vector<int>(inliers));
Eigen::VectorXf modelParas;
ransac.getModelCoefficients(modelParas);
std::cout << modelParas<< "\n\n";
qDebug()<<modelParas(0);
qDebug()<<modelParas(1);
qDebug()<<modelParas(2);
qDebug()<<"002!";
// Get points and delete points 2D
pcl::ExtractIndices<pcl::PointXYZ> Circle_extract;
Circle_extract.setInputCloud(Src_Cloud_Planar);// Enter the point cloud
Circle_extract.setIndices(tempinliers);
Circle_extract.setNegative(false);
Circle_extract.filter(*Circle2D);//line2D Split this time 2D Line --
// Delete point
Circle_extract.setNegative(true);
Circle_extract.filter(*tempRemain);
*Src_Cloud_Planar = *tempRemain;// The remaining point clouds this time --
// If you can't find a circle , sign out
if(inliers.size()<=60)
{
viewer2.close();
continue;
}
// Draw a circle
QVector<pcl::PointXYZ> points;
double o_x = modelParas(0), o_y=modelParas(1), r = modelParas(2); // Center and radius of circle
for (int i = 0; i < 100; i++) // Calculate the coordinates of points on the ring
{
pcl::PointXYZ point;
double alpha = 2 * M_PI / (100 - 1);
point.x = o_x + r * cos(i * alpha);
point.y = o_y + r * sin(i * alpha);
point.z = 0;
points.push_back(point);
}
// Connect the points on the ring with line segments
for (int i = 0; i < points.size() - 1; i++)
{
viewer2.addLine(points.at(i), points.at(i + 1), QString("CircleLineX%1").arg(index).toStdString(), 0);
index=index+1;
}
viewer2.addLine(points.at(points.size() - 1), points.at(0), QString("CircleLineX%1_%2").arg(points.size()).arg(5).toStdString(), 0);
index=index+1;
//------------------- Visualization of original point cloud and filtered target point cloud ------------------------
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(Src_Cloud_Planar, 0, 255, 0);
viewer2.addPointCloud<pcl::PointXYZ>(Src_Cloud_Planar, single_color, "Source clouds");
while (!viewer2.wasStopped())
{
viewer2.spinOnce(1);
}
}
qDebug()<<"003!";
while (!viewer00.wasStopped())
{
viewer00.spinOnce(1);
}
Two 、 Straight line detection
// Straight line is obtained through filtering ( After deleting , Just cycle many times )
pcl::PointCloud<pcl::PointXYZ>::Ptr line2D(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_f2D(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr ptCloud2D(new pcl::PointCloud<pcl::PointXYZ>);
// Create a model parameter object , Used to record results
pcl::ModelCoefficients::Ptr coefficients3(new pcl::ModelCoefficients);
//inliers Indicates the point where the error can be tolerated Record the serial number of the point cloud
pcl::PointIndices::Ptr inliers3(new pcl::PointIndices);
// Create a splitter
pcl::SACSegmentation<pcl::PointXYZ> seg;
// Optional
seg.setOptimizeCoefficients(true);
// Mandatory- Set the target geometry
seg.setModelType(pcl::SACMODEL_LINE);//SACMODEL_LINE SACMODEL_PLANE notes : Modify the model name here
// Segmentation method : Random sampling
seg.setMethodType(pcl::SAC_RANSAC);//SAC_RANSAC
// The maximum number of iterations
seg.setMaxIterations(100);
// Set the error tolerance range
seg.setDistanceThreshold(0.0005);// notes : Fill in the specific value
// Enter the point cloud
seg.setInputCloud(Tgt_Cloud_Planar);// Enter the point cloud
// Split point cloud
seg.segment(*inliers3, *coefficients3);
// Get points and delete points 2D
pcl::ExtractIndices<pcl::PointXYZ> extract2;
extract2.setInputCloud(Tgt_Cloud_Planar);// Enter the point cloud
extract2.setIndices(inliers3);
extract2.setNegative(false);
extract2.filter(*line2D);//line2D Split this time 2D Line --
// Delete point ( notes : If you recognize multiple lines , Then delete the identified power line point cloud , Then the cycle )
extract2.setNegative(true);
extract2.filter(*cloud_f2D);
*ptCloud2D = *cloud_f2D;//ptCloud2D The remaining point clouds this time --
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color3(line2D, 0, 0, 0);
viewer00.addPointCloud<pcl::PointXYZ>(line2D, single_color3, "Target clouds90");
// Connect the points on the line with line segments
for (int i = 0; i < line2D->size() - 1; i++)
{
viewer00.addLine(line2D->points[i], line2D->points[i+1], QString("LineX%1").arg(i).toStdString(), 0);
}
viewer00.addLine(line2D->points[line2D->size() - 1], line2D->points[0], QString("LineX%1_%2").arg(line2D->size()).arg(5).toStdString(), 0);
qDebug()<<"size"<<line2D->size();
qDebug()<<"003!";
while (!viewer00.wasStopped())
{
viewer00.spinOnce(1);
}
边栏推荐
- invalid syntax
- We media people must have four material websites, and don't worry about finding materials anymore
- The difference between "= =" and equals
- 贴片微型滚珠振动开关的结构原理
- 第二周学习:卷积神经网络
- 汇编语言与微机原理实验一、实验二、实验三:分支程序设计/循环程序设计/子程序设计
- Learning notes of technical art hundred people plan (2) -- vector
- [paper notes] a meta reinforcement learning algorithm for causal discovery
- AI首席架构师12-AICA-工业生产过程优化场景下产业落地解析
- DHCP first static experiment
猜你喜欢
![[paper notes] a meta reinforcement learning algorithm for causal discovery](/img/03/84462b38551c41173f7a9734cb0e99.png)
[paper notes] a meta reinforcement learning algorithm for causal discovery

【论文笔记】基于在线预测和规划的机器人动态跟踪抓取方法

单元测试,写起来到底有多痛?

Matrixcube unveils the complete distributed storage system matrixkv implemented in 102-300 lines

Kibana~后台启动Kibana之后无法找到进程号
![[MySQL rights] UDF rights (with Malaysia)](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[MySQL rights] UDF rights (with Malaysia)

3 lexical analysis

Network Security Learning (XV) ARP

DOM event binding

第二周学习:卷积神经网络
随机推荐
Can generic types be used in array
每周推荐短视频:需要协同的智能设备越来越多,给物联网开发提出更大挑战?
Qtreewidget control of QT
IPFs of Internet Protocol
We media people must have four resource tools, each of which is very practical
JS makes elements get or lose focus
单模型常识推理首超人类!HFL登顶OpenBookQA挑战赛
贴片微型滚珠振动开关的结构原理
DOM event binding
CUDA environment construction
Code shoe set precision barrage
PE format: analyze and implement IATHOOK
uvm_hdl——DPI在UVM中的实现(四)
Websocket summary
What are the differences between FileInputStream and bufferedinputstream?
The difference between abstract classes and interface interfaces
ribbon 执行逻辑源码解析
7-1 understand everything
BIO、NIO、AIO的区别?
【论文笔记】基于在线预测和规划的机器人动态跟踪抓取方法