点云技术相关产学研社区

 找回密码
 立即注册加入PCL中国点云技术相关产学研社区

扫一扫,访问微社区

查看: 3262|回复: 3

las格式的点云文件转换为PCD格式文件程序源码

[复制链接]
发表于 2015-5-27 10:54:30 | 显示全部楼层 |阅读模式
las是一种常用的点云文件格式,例子程序把las格式转换成基础PCD格式文件,转换过程中激光的反射率舍弃了。
回复

使用道具 举报

 楼主| 发表于 2015-5-27 11:51:05 | 显示全部楼层

#include "stdafx.h"

#include <iostream>
#include <boost/thread/thread.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/console/parse.h>
#include  "lasreader.h"
using namespace std;
int writePCD(string fileName,pcl::PointCloud<pcl::PointXYZ>::Ptr cloud)
{

        //pcl::io::savePCDFileASCII(fileName,cloud);
        pcl::io::savePCDFileBinary(fileName,*cloud);
        return(0);
}
int main (int argc, char** argv)
{

        pcl::PointCloud<pcl::PointXYZ>::Ptr basic_cloud_ptr (new pcl::PointCloud<pcl::PointXYZ>);

        //read  las file
        string file_name;
        file_name="scan043.las";
        FILE *file_in;
        file_in=fopen(file_name.c_str(),"rb");            

        lasreader *lasread;
        lasread=new lasreader();
        if ( (lasread->open(file_in) == false) || file_in==0 )
        {
                return 0;
        }

        float boundingBoxMin[3];   
        float boundingBoxMax[3];   


        boundingBoxMin[0] = lasread->header.min_x;                                                                    
        boundingBoxMin[1] = lasread->header.min_y;                                                                    
        boundingBoxMin[2] = lasread->header.min_z;                                                                    

        boundingBoxMax[0] = lasread->header.max_x;                                                                    
        boundingBoxMax[1] = lasread->header.max_y;                                                                    
        boundingBoxMax[2] = lasread->header.max_z;   

        double midx,midy,midz;
        midx=(lasread->header.max_x+lasread->header.min_x)/2;
        midy=(lasread->header.max_y+lasread->header.min_y)/2;
        midz=(lasread->header.max_z+lasread->header.min_z)/2;
        int p_count = lasread->npoints;
        lasread->open_skipheader();
        //p_count=5;
        LASpt pt;
        unsigned char r(255), g(15), b(15);
        while (lasread->p_count < p_count)
        {
                if (lasread->read_point(&pt))
                {
                        pcl::PointXYZ basic_point;
                        basic_point.x = pt.x-midx;
                        basic_point.y = pt.y-midy;
                        basic_point.z = pt.z-midz;
                        basic_cloud_ptr->points.push_back(basic_point);

                       
                }
                else
                {
                        break;
                }
        }


        //write PCDFile
        string PCDfileName="las2pcd043.pcd";
        writePCD(PCDfileName,basic_cloud_ptr);

        return 0;
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-27 11:52:34 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册加入PCL中国点云技术相关产学研社区

x
回复 支持 反对

使用道具 举报

发表于 2016-4-19 10:29:55 | 显示全部楼层
不错,学习,
回复 支持 反对

使用道具 举报

本版积分规则

QQ|小黑屋|点云技术相关产学研社区 ( 陕ICP备13001629号 )

GMT+8, 2024-5-14 04:08 , Processed in 1.286176 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表