生成带有rgb值的pcd文件并显示
来源:互联网 发布:php 面相过程 编辑:程序博客网 时间:2024/06/05 04:32
pcd文件中的格式为x y z rgb而不是分开的r g b,所以在原数据的基础上要进行变形,
由r g b得到rgb(float):int rgb = ((int)r << 16 | (int)g << 8 | (int)b); 式中的“<<”为左移符号;
由rgb得到r g b(int):int r = (rgb >> 16) & 0x0000ff;
int g = (rgb >> 8) & 0x0000ff;
int b = (rgb) & 0x0000ff;
一个自己写的例子:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
char *filepath=" "; //自己添加
double array[][]={NULL}; 自己添加
FILE *fp;
int main (int argc, char** argv)
{
if((fp=fopen(filepath,"r"))==NULL)
{ printf("can not open %s",filepath);
}
pcl::PointCloud<pcl::PointXYZRGB> cloud;
cloud.width = ; 数组的行数
cloud.height = 1;
cloud.is_dense = false;
cloud.points.resize (cloud.width * cloud.height);
while(!feof(fp))
{
for (int m=0;m< ;++m)
{
int frgb=0;
fscanf(fp,"%lf %lf %lf %lf %lf %lf",&array[m][0],&array[m][1],&array[m][2],&array[m][3],&array[m][4],&array[m][5]);//后面三列的输入类型也要为lf。
cloud.points[m].x = array[m][0];
cloud.points[m].y = array[m][1];
cloud.points[m].z = array[m][2];
frgb=((int)array[m][3]<<16|(int)array[m][4]<<8|(int)array[m][5]);
cloud.points[m].rgb=*reinterpret_cast<float*>(&frgb);//frgb在这由int型转换成了float型。
//reinterpret_cast()为指针类型转换。
}
}
fclose(fp);
pcl::io::savePCDFileASCII (" ", cloud);
std::cerr << "already save " << cloud.points.size () << " data points to myrgbpointS3.pcd" << std::endl;
return 0;
}
显示点云就比较简单了,只要pcd没有问题,就可以正常显示,代码如下:
/*
*GreedyProjection是根据点云进行三角化,而possion则是对water-tight的模型进行重建
*形成了封闭的mesh和很多冗余信息,需要对possion的重建进行修剪才能得到相对正确的模型
*/
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/vtk_io.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/features/normal_3d.h>
#include <pcl/surface/gp3.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
int main (int argc, char** argv)
{
// Load input file into a PointCloud<T> with an appropriate type
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
if(pcl::io::loadPCDFile<pcl::PointXYZRGB>(" ",*cloud)==-1)//打开点云文件
{
PCL_ERROR("Couldn't read file\n");
return -1;
}
//显示结果图
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer("3D Viewer"));
viewer->setBackgroundColor(1,1,1); //设置背景
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(cloud);
viewer->addPointCloud<pcl::PointXYZRGB> (cloud, rgb, "my cloud"); //添加点云
viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "my cloud"); //设置点的大小
viewer->addCoordinateSystem(1000.0); //设置坐标系的大小
viewer->initCameraParameters();
while(!viewer->wasStopped())
{
viewer->spinOnce(100);
boost::this_thread::sleep (boost::posix_time::microseconds(100000));
}
// Finish
return 0;
}
- 生成带有rgb值的pcd文件并显示
- 2 pcl读取pcd文件并显示
- 点云pcd文件的生成
- 生成pcd文件
- PCL生成.PCD文件
- XYZRGB型PCD文件中rgb字段的加包与拆包
- 读取图片并显示每个像素处的RGB值
- .pcd文件的书写格式
- .pcd文件的书写格式
- 如何生成vfh特征值pcd文件
- java中获得RGB值 并显示
- 将自己得到的数据从txt文档中读入,生成pcd文件
- 从Xtion(Kinect)生成的PCD文件中读取点云数据
- 带有进度显示的文件拷贝模块
- PCLlab(1)基于MFC单文档框架的pcd文件显示
- 基于+文件流的txt点云转pcd
- PCD点云文件的读取
- 如何打印并分页显示带有滚动条的datagridview
- POST提交方式中文乱码的解决方案
- Fresco 源码解析 - 利用 @DoNotSkip 来防止混淆
- Java -- JavaBean,POJO,VO,DTO的区别和联系
- iOS-本地换肤思路
- linux基础目录结构
- 生成带有rgb值的pcd文件并显示
- 文章标题
- Android开发 如何快速实现分享功能
- Oracle V$SESSION详解
- Android开发技术学习之popupwindow的弹窗实现
- 实用知识:音乐播放的方法使用
- 虚拟机性能监控与故障处理工具
- 打开MySQL数据库远程访问的权限
- MySQL基础操作汇总