C++ PCL:在投影点云数据为0时中断拟合椭圆
///'给下列代码添加上如果投影数据为0,则中断的代码//ncv::Point2f convertPoint(const pcl::PointXYZRGB& point)//n{//n//treturn cv::Point2f(point.x, point.y);//n}//n//n// Fit ellipse using OpenCV//ncv::RotatedRect fitEllipse(const pcl::PointCloudpcl::PointXYZRGB::Ptr& cloud)//n{//n//t// Convert PointCloud to vector of Point2f//n//tstd::vectorcv::Point2f points;//n//tfor (const auto& point : cloud->points) //n//t{//n//t//tpoints.push_back(convertPoint(point));//n//t}//n//n//tif (points.size() == 0) {//n//t//t// 如果投影数据为0,则中断//n//t//treturn cv::RotatedRect();//n//t}//n//n//t// Fit ellipse using OpenCV//n//treturn cv::fitEllipse(points);//n}//npcl::ProjectInlierspcl::PointXYZRGB proj; //n//t//tproj.setModelType(pcl::SACMODEL_PLANE);//n//t//tproj.setInputCloud(Ptrr);//n//t//tproj.setModelCoefficients(coefficients);//n//t//tproj.filter(*touy);//n//t//t//pcl::io::savePLYFileASCII(/'E:////dianyun////put12.ply/', *touy);//n//n//t//t//可视化//n//t//t//boost::shared_ptrpcl::visualization::PCLVisualizer viewer(new pcl::visualization::PCLVisualizer(/'cloud show/'));//n//t//t//int v1 = 0;//n//t//t//int v2 = 1;//n//t//t//viewer->createViewPort(0, 0, 0.5, 1, v1);//n//t//t//viewer->createViewPort(0.5, 0, 1, 1, v2);//n//t//t//viewer->setBackgroundColor(1, 1, 1, v1);//n//t//t//viewer->setBackgroundColor(1, 1, 1, v2);//n//t//t////原始点云绿色//n//t//t//pcl::visualization::PointCloudColorHandlerCustompcl::PointXYZRGB src_h(Ptrr, 0, 255, 0);//n//t//t////投影后的点云//n//t//t//pcl::visualization::PointCloudColorHandlerCustompcl::PointXYZRGB pro_cloud(touy, 0, 0, 255);//n//t//t////viewer->setBackgroundColor(255, 255, 255);//n//t//t//viewer->addPointCloud(Ptrr, src_h, /'cloud/', v1);//n//t//t//viewer->addPointCloud(touy, pro_cloud, /'pro_cloud/', v2);//n//t//t//while (!viewer->wasStopped())//n//t//t//{//n//t//t////tviewer->spinOnce(100);//n//t//t////tboost::this_thread::sleep(boost::posix_time::microseconds(10000));//n//t//t//}//n//n//t//t//根据投影的点云数据拟合椭圆,使用//n//t//t// Fit ellipse//n//t//tcv::RotatedRect ellipse = fitEllipse(touy);//n//t//t//n//t//t// Output major and minor axes//n//t//tstd::cout << /'Major axis: /' << ellipse.size.width << std::endl;//n//t//tstd::cout << /'Minor axis: /' << ellipse.size.height << std::endl;/
原文地址: https://www.cveoy.top/t/topic/p1fC 著作权归作者所有。请勿转载和采集!