一.pcl+ros实现90度分割.前文有说明,略微修改,批量处理.

#include <iostream>
#include <string.h>
#include <string>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/conversions.h>#include <pcl_ros/transforms.h>#include <pcl/filters/extract_indices.h>#include <sensor_msgs/PointCloud2.h>
#include<pcl/io/pcd_io.h>//which contains the required definitions to load and store point clouds to PCD and other file formats.
#include <pcl/io/pcd_io.h>//PCL的PCD格式文件的输入输出头文件
#define CLIP_COR 0 //     x  zuobiaovoid clip_above(double clip_cor, const pcl::PointCloud<pcl::PointXYZI>::Ptr in,const pcl::PointCloud<pcl::PointXYZI>::Ptr out)
{pcl::ExtractIndices<pcl::PointXYZI> cliper;cliper.setInputCloud(in);pcl::PointIndices indices;
#pragma omp forfor (size_t i = 0; i < in->points.size(); i++){if (in->points[i].x < clip_cor){indices.indices.push_back(i);}}cliper.setIndices(boost::make_shared<pcl::PointIndices>(indices));cliper.setNegative(true); //ture to remove the indicescliper.filter(*out);
}void clip_xy(const pcl::PointCloud<pcl::PointXYZI>::Ptr in,const pcl::PointCloud<pcl::PointXYZI>::Ptr out)
{pcl::ExtractIndices<pcl::PointXYZI> cliper;cliper.setInputCloud(in);pcl::PointIndices indices;
#pragma omp forfor (size_t i = 0; i < in->points.size(); i++){if (abs(in->points[i].x) < abs(in->points[i].y)){indices.indices.push_back(i);}}cliper.setIndices(boost::make_shared<pcl::PointIndices>(indices));cliper.setNegative(true); //ture to remove the indicescliper.filter(*out);
}int
main (int argc, char** argv)
{pcl::PointCloud<pcl::PointXYZI>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZI>);// Fill in the cloud datapcl::PCDReader reader;// Replace the path below with the path where you saved your fileint i=1;for( i; i < 10; i = i + 1 ){char *filename = new char[25];char *filename2 = new char[25];sprintf(filename,"%d.pcd",i);reader.read (filename, *cloud); // Remember to download the file first!std::cerr << "PointCloud before filtering: " << cloud->width * cloud->height << " data points (" << pcl::getFieldsList (*cloud) << ").";pcl::PointCloud<pcl::PointXYZI>::Ptr cliped_pc_ptr(new pcl::PointCloud<pcl::PointXYZI>);clip_above(CLIP_COR, cloud, cliped_pc_ptr);pcl::PointCloud<pcl::PointXYZI>::Ptr remove_close(new pcl::PointCloud<pcl::PointXYZI>);clip_xy(cliped_pc_ptr, remove_close); std::cerr << "PointCloud after filtering: " << remove_close->width * remove_close->height << " data points (" << pcl::getFieldsList (*remove_close) << ").";pcl::PCDWriter writer;sprintf(filename2,"%d_new.pcd",i);writer.write (filename2, *remove_close, false);}return (0);
}

这个程序中有两点要说明:

1.Pcd点云格式的读取

pcl::PCDReader reader

reader.read(filename,datapointcloudname)

pcl::PCDWriter writer

writer.write(filename,datapointcloud)

2.连续读取文件名称顺序增加的代码

int i=1;for( i; i < 10; i = i + 1 ){char *filename = new char[25];sprintf(filename,"%d.pcd",i);reader.read (filename, *cloud); // Remember to down

3.如何在利用ros完成c++的编译和运行

1)    在工作空间catkin_make,source,得到node节点.编译

2) 在文件所在文件夹中 roscore,rosrun package_name node_name.运行.




二.python 进行球面投影.


1.点云预处理

该部分来自adamshan大佬,博客地址https://blog.csdn.net/AdamShan/article/details/83544089

传统的CNN设计多用于二维的图像模式识别(宽 × 高 ×× 通道数),三维的点云数据格式不符合该模式,而且点云数据稀疏无规律,这对特征提取都是不利的,因此,在将数据输入到CNN之前,首先对数据进行球面投影,从而到一个稠密的、二维的数据,球面投影示意图如下:

其中,ϕ和θ 分别表示点的方位角(azimuth)和顶角(altitude),这两个角如下图所示:

通常来说,方位角是相对于正北方向的夹角,但是,在我们Lidar的坐标系下,方位角为相对于x方向(车辆正前方)的夹角,ϕ和θ 的计算公式为:

其中,(x,y,z) 为三维点云中每一个点的坐标。所以对于点云中的每一个点都可以通过其 (x,y,z)计算其(θ,ϕ) ,也就是说我们将三维空间坐标系中的点都投射到了一个球面坐标系,这个球面坐标系实则已经是一个二维坐标系了,但是,为了便于理解,我们对其角度进行微分化从而得到一个二维的直角坐标系:

那么,球面坐标系下的每一个点都可以使用一个直角坐标系中的点表示,如下:

通过这么一层变换,我们就将三维空间中任意一点的位置 (x,y,z)投射到了2维坐标系下的一个点的位置 (i,j) 我们提取点云中每一个点的5个特征: (x,y,z,intensity,range)放入对应的二维坐标 (i,j)内。从而得到一个尺寸为 (H,W,C) 张量(其中 5C=5),由于论文使用的是Kitti的64线激光雷达,所以 H=64 ,水平方向上,受Kitti数据集标注范围的限制,原论文仅使用了正前方90度的Lidar扫描,使用512个网格对它们进行了划分(即水平上采样512个点)。所以,点云数据在输入到CNN中之前,数据被预处理成了一个尺寸为 (64×512×5) 的张量。


2.代码实现

import numpy as np
import mathdef pcd2npy(filename):m = np.empty((64, 512, 6))f = open(filename, 'r')line = f.readlines()for i in range(11,len(line)-1):a,b,c,d=line[i].split(' ',3)x=float(a)y=float(b)z=float(c)intensity=float(d)r = np.sqrt(x ** 2 + y ** 2 + z ** 2)  # Map Distance from sensorr_xy=np.sqrt(x ** 2 + y ** 2)theta=math.asin(z/r)* 180/math.piif(theta<0):theta+=30fi=math.asin(y/r_xy)* 180/math.piif(fi<0):fi+=90theta_num = theta / 0.46875fi_num = fi / 0.17578125g = math.ceil(theta_num)-1j = math.ceil(fi_num)-1m[g][j][0] = xm[g][j][1] = ym[g][j][2] = zm[g][j][3] = intensitym[g][j][4] = rm[g][j][5] = 0.0return mk=0
for k in range(9):npyfile=pcd2npy("%01d"%k+"_new.pcd")np.save("%01d" % k + "_new.npy", npyfile)k+=1

1)pcd文件读取并按照4个一组划分.

2)按顺序读取文件名表达

"%01d" % k + "_new.npy"  k本身占%01d字符,所以表达应该是 1_new.npy

3)pcd文本样式查看,用open with text editor.打开如下,是从第12行开始是点云.

4)调节微分数,未完待续.

总结:

1)bin转pcd(pcl+ros)

2)点云分割(pcl+ros)

3)球面投影(python)

pointcloud90度分割+球面投影(pcl+ros+python)相关推荐

  1. 斯坦福的著名小兔子模型的点云数据_传统方法的点云分割以及PCL中分割模块

    之前在微信公众号中更新了以下几个章节 1,如何学习PCL以及一些基础的知识 2,PCL中IO口以及common模块的介绍 3,  PCL中常用的两种数据结构KDtree以及Octree树的介绍 有兴趣 ...

  2. Open3D 区域生长分割:详解Python实现过程

    Open3D 区域生长分割:详解Python实现过程 Open3D是一个专业的开源三维计算机视觉库,支持针对点云数据进行多种类型算法处理及可视化.其中包括基于区域生长分割的算法,可以对点云数据进行自动 ...

  3. ROS python编程

    ROS python编程 ROS 初始化ROS环境 创建ROS节点 使用Python创建多个Marker ROS 由于python中包含大量的库,这里将ros与python结合进行编程. 初始化ROS ...

  4. 文本相似度算法的对比及python实现

    文本相似度算法的对比及python实现 前言 通常我们有这样的需求:对两篇文章或者产品内容进行重复率查询. 为了解决类似的问题,罗列了一些常见的相似度算法,用python代码实现. 五种常见的相似度算 ...

  5. 传统方法的点云分割以及PCL中分割模块

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 摘要 三维点云分割是将同属性的点云物体分割出来,以便于单独对该点云 ...

  6. 文本相似度计算——Simhash算法(python实现)

    互联网网页存在着大量重复内容,必须有一套高效的去重算法,否则爬虫将做非常多的无用功,工作时效性无法得到保证,更重要的是用户体验也不好.业界关于文本指纹去重的算法众多,如 k-shingle 算法.go ...

  7. [简单题]换一个思维,代码简洁度就完全变了(Python实现)

    题目名字: Human readable duration format 原题链接: https://www.codewars.com/kata/human-readable-duration-for ...

  8. python dicom 器官分割_图像识别 | 使用Python对医学Dicom文件的预处理(含代码)

    前沿 在处理医学图像时,常常会遇到以Dicom格式保存的医学图像,如CT.MRI等.Dicom文件是需要专门的软件或者通过编程,应用相应的库进行处理.为了能够更好地服务下游任务,例如分割或检测腹腔CT ...

  9. PCL:python pcl解码RGB- point_cloud2.read_points rgb

    参考:https://answers.ros.org/question/344096/subscribe-pointcloud-and-convert-it-to-numpy-in-python/ r ...

  10. python 字符串分割_如何使用python语言split方法对不同字符串分割

    在JavaScript中,可以使用split()将字符串分割成字符串数组:而在python语言中,split()方法也可以将字符串进行分割,分割之后的结果放置在列表中.下面利用几个实例说明split( ...

最新文章

  1. Unity3D热更新全书-脚本(二) 两级分化
  2. Java.util包中常用的类
  3. mysql中int(m)_mysql中int(M) tinyint(M)中M的作用
  4. js如何判断当前文本的输入状态——中文输入法的那些坑
  5. Window 7 下的某些服务不能随便禁用! 无法立即删除.exe文件,因为禁用了Application Experience服务。...
  6. SQL Server 中索引的禁用与删除
  7. 企业级OpenCV、图像识别资料免费下载,仅此1天!
  8. 蒟蒻吃药计划-治疗系列 #round6 数据结构初步-指针|链表|结构体
  9. jq实现文字个数限制_限制字符输入数功能(jquery版和原生JS版)
  10. Linux常用命令大全
  11. matlab 入门 mobi,MATLAB基础教程 pdf epub mobi txt 下载
  12. Visio帮你轻松画出3D效果示意图
  13. 数商云医药行业SCM供应链管理系统应用场景、运用模式
  14. 学习matlab(十七)——信号处理
  15. 新手小白,做二次剪辑的必备工具,帮你快人一步
  16. UDE2021未来生活领袖峰会:视像行业发展趋势研究报告发布
  17. python根据经纬度画热力图_【python】使用python按照一定格式批量输出,地图热力图经纬度格式生成器...
  18. python中for循环打印菱形_Python 使用双重循环打印图形菱形操作
  19. robocup初学(第一篇)
  20. 2.12父子进程通过匿名管道通信

热门文章

  1. Java拾遗补阙 ----- Super、This关键字使用总结
  2. 货车超载计算公式用计算机怎么算,超载计算公式
  3. Matlab用saveas函数自动编号保存图片
  4. u检验中的查u界值表_u检验、t检验、F检验、X2检验
  5. STM32H743中的DCMI无法进入行中断和场中断问题
  6. 基于流计算 Oceanus 和 Elasticsearch Service 构建百亿级实时监控系统
  7. 跑马灯的一些使用心得
  8. css超链接样式+雪碧图实现导航
  9. css兼容360浏览器极速,CSS hack 360浏览器 极速模式与兼容模式
  10. Python生成字符视频