基于RGB_D图像的现场点云分割(d435i c++ pcl)

摘要

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

实现

现场ply文件捕捉实现:

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


#include <iostream>
#include <vector>
#include <pcl/point_types.h>
#include <pcl/search/search.h>
#include <pcl/search/kdtree.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/passthrough.h>
#include <pcl/segmentation/region_growing_rgb.h>
#include <pcl/console/print.h>
#include <pcl/console/parse.h>
#include <pcl/console/time.h>
#include <pcl/features/normal_3d.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/filters/voxel_grid.h>

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<pcl::PointXYZRGB>::Ptr cloud_t(new pcl::PointCloud<pcl::PointXYZRGB>);
	pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);

	pcl::VoxelGrid<pcl::PointXYZRGB> 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<<cloud->points.size()<<endl;
	pcl::search::Search <pcl::PointXYZRGB>::Ptr tree = boost::shared_ptr<pcl::search::Search<pcl::PointXYZRGB> >(new pcl::search::KdTree<pcl::PointXYZRGB>);


	pcl::search::Search<pcl::PointXYZRGB>::Ptr tree1 = boost::shared_ptr<pcl::search::Search<pcl::PointXYZRGB> >(new pcl::search::KdTree<pcl::PointXYZRGB>);
	pcl::PointCloud <pcl::Normal>::Ptr normals(new pcl::PointCloud <pcl::Normal>);
	pcl::NormalEstimation<pcl::PointXYZRGB, pcl::Normal> 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): %d\n", diff[1]);

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

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

	pcl::RegionGrowingRGB<pcl::PointXYZRGB> 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 <pcl::PointIndices> clusters;
	reg.extract(clusters);
	end = time(0);
	diff[2] = difftime(end, start) - diff[0] - diff[1];
	PCL_INFO("\tRGB region growing takes(seconds): %d\n", diff[2]);

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

	pcl::PointCloud <pcl::PointXYZRGB>::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模型的前提下,通过提取点对或者法向特征完成统计后与现场各个点云聚类比较,实现现场聚类筛选。

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
根据引用\[1\]中的描述,可以使用基于RGB信息的区域生长分割算法对Realsense D435i相机获取的现场图像进行快速分割。首先,使用D435i相机获取现场RGB和Depth信息生成带有彩色信息的点,并对点进行下采样。然后,对约简后的点进行分割,实现点分割操作。 在使用Realsense D435i相机时,可以按照引用\[2\]中的指导进行操作。首先,在终端中运行命令"roslaunch realsense2_camera rs_camera.launch"来启动相机。然后,在rviz中修改全局坐标系,将Fixed Frame一栏改为"camera_color/depth_",并添加相机,选择上述realsense包发布的话题进行订阅,即可看到点分割的效果。 如果需要使用OpenCV来判断物体的方向,可以参考引用\[3\]中的direction_func.py。该脚本使用OpenCV来判断物体的方向,通过计算物体的中心点坐标(cenx, ceny)和深度像素(depth_pixel)来获取物体的方向信息。 综上所述,可以使用Realsense D435i相机进行点分割操作,并可以结合OpenCV来判断物体的方向。 #### 引用[.reference_title] - *1* [基于RGB_D图像现场分割(d435i c++ pcl)](https://blog.csdn.net/m0_56838271/article/details/121158460)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Realsense D435用rviz查看点信息](https://blog.csdn.net/No_vegetable/article/details/124555837)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Intel RealSense D435i深度相机通过点获取图片中任意点三维信息(python实现)](https://blog.csdn.net/weixin_49828565/article/details/127051358)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wdmcs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值