给下列代码添加一个if语句条件是pclPointCloudpclPointXYZRGBPtr Ptrrnew pclPointCloudpclPointXYZRGB的点数大于0才执行下列代码pclModelCoefficientsPtr coefficientsnew pclModelCoefficients; coefficients-valuesresize4; coefficient
可以在代码的开头添加一个if语句,判断点云的点数是否大于0,如果是,则执行下列代码,否则不执行。代码如下:
if (Ptrr->size() > 0) { pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients()); coefficients->values.resize(4); coefficients->values[0] = 1; coefficients->values[1] = 0; coefficients->values[2] = 1; coefficients->values[3] = 0; // --------------创建滤波器对象------------------- pcl::ProjectInlierspcl::PointXYZRGB proj; proj.setModelType(pcl::SACMODEL_PLANE); proj.setInputCloud(Ptrr); proj.setModelCoefficients(coefficients); proj.filter(*touy); //pcl::io::savePLYFileASCII("E:\dianyun\put12.ply", *touy);
//可视化
//boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("cloud show"));
//int v1 = 0;
//int v2 = 1;
//viewer->createViewPort(0, 0, 0.5, 1, v1);
//viewer->createViewPort(0.5, 0, 1, 1, v2);
//viewer->setBackgroundColor(1, 1, 1, v1);
//viewer->setBackgroundColor(1, 1, 1, v2);
////原始点云绿色
//pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> src_h(Ptrr, 0, 255, 0);
////投影后的点云
//pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> pro_cloud(touy, 0, 0, 255);
////viewer->setBackgroundColor(255, 255, 255);
//viewer->addPointCloud(Ptrr, src_h, "cloud", v1);
//viewer->addPointCloud(touy, pro_cloud, "pro_cloud", v2);
//while (!viewer->wasStopped())
//{
// viewer->spinOnce(100);
// boost::this_thread::sleep(boost::posix_time::microseconds(10000));
//}
//根据投影的点云数据拟合椭圆,使用
// Fit ellipse
cv::RotatedRect ellipse = fitEllipse(touy);
// Output major and minor axes
std::cout << "Major axis: " << ellipse.size.width << std::endl;
std::cout << "Minor axis: " << ellipse.size.height << std::endl;
原文地址: http://www.cveoy.top/t/topic/ii75 著作权归作者所有。请勿转载和采集!