栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

基于RGB

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于RGB

摘要

本文使用基于RGB信息的区域生长分割算法完成对现场图像的快速分割(小于1s)。首先使用D435i相机获取现场RGB和Depth信息生成带有彩色信息的点云,并获取点云进行下采样,之后对约简点云进行分割。

实现

现场ply文件捕捉实现:

(6条消息) 利用IntelRealSense D435i 提取一帧pcl::PointXYZRGB图像(C++)_m0_56838271的博客-CSDN博客

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main(int argc, char** argv)
{
	bool Bool_Cuting = false, b_n = false;
	int MinClusterSize = 600, KN_normal = 50;
	float far_cuting = 10, near_cuting = 0, DistanceThreshold = 10.0, ColorThreshold = 6, RegionColorThreshold = 5, SmoothnessThreshold = 30.0, CurvatureThreshold = 0.05;
	
	pcl::PointCloud::Ptr cloud_t(new pcl::PointCloud);
	pcl::PointCloud::Ptr cloud(new pcl::PointCloud);

	pcl::VoxelGrid sor;
	
	time_t start, end, diff[5], option;//计时相关

	pcl::io::loadPCDFile("colorful.pcd", *cloud_t);

	sor.setInputCloud(cloud_t);
	sor.setLeafSize(0.005f, 0.005f, 0.005f);
	sor.filter(*cloud);
	cout<points.size()<::Ptr tree = boost::shared_ptr >(new pcl::search::KdTree);


	pcl::search::Search::Ptr tree1 = boost::shared_ptr >(new pcl::search::KdTree);
	pcl::PointCloud ::Ptr normals(new pcl::PointCloud );
	pcl::NormalEstimation normal_estimator;
	normal_estimator.setSearchMethod(tree);
	normal_estimator.setInputCloud(cloud);
	normal_estimator.setKSearch(KN_normal);
	normal_estimator.compute(*normals);
	end = time(0);
	diff[1] = difftime(end, start) - diff[0];
	PCL_INFO("tEstimating normal takes(seconds): %dn", diff[1]);

	pcl::IndicesPtr indices(new std::vector );
	if (Bool_Cuting)
	{

		pcl::PassThrough pass;
		pass.setInputCloud(cloud);
		pass.setFilterFieldName("z");
		pass.setFilterLimits(near_cuting, far_cuting);
		pass.filter(*indices);
	}

	pcl::RegionGrowingRGB reg;
	reg.setInputCloud(cloud);
	if (Bool_Cuting)reg.setIndices(indices);
	reg.setSearchMethod(tree);
	reg.setDistanceThreshold(DistanceThreshold);
	reg.setPointColorThreshold(ColorThreshold);
	reg.setRegionColorThreshold(RegionColorThreshold);
	reg.setMinClusterSize(MinClusterSize);
	if (b_n)
	{
		reg.setSmoothModeFlag(true);
		reg.setCurvatureTestFlag(true);

		reg.setInputNormals(normals);
		reg.setSmoothnessThreshold(SmoothnessThreshold / 180.0 * M_PI);
		reg.setCurvatureThreshold(CurvatureThreshold);
	}
	std::vector  clusters;
	reg.extract(clusters);
	end = time(0);
	diff[2] = difftime(end, start) - diff[0] - diff[1];
	PCL_INFO("tRGB region growing takes(seconds): %dn", diff[2]);

	std::cout << "number of cluster : " << clusters.size() << std::endl;

	pcl::PointCloud ::Ptr colored_cloud = reg.getColoredCloud();
	pcl::visualization::CloudViewer viewer("基于颜色的区域生长算法实现点云分割");
	viewer.showCloud(colored_cloud);
	while (!viewer.wasStopped())
	{
		boost::this_thread::sleep(boost::posix_time::microseconds(100));
	}
	return 0;
}

此处参考:点云下采样;基于RGB的区域生长;

结果

工作展望

下一步在给定茶杯CAD模型的前提下,通过提取点对或者法向特征完成统计后与现场各个点云聚类比较,实现现场聚类筛选。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/429785.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号