0

我在VS2017上用laslib库重采样点云。在Debug环境下运行后出现以下错误。我试图将属性表中的运行时调整为“多线程调试DLL(/MDd)”,但是这个错误还存在。这是我的代码,请帮我看看问题出在哪里

在此处输入图像描述

#include <fstream>
#include <liblas/liblas.hpp>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/keypoints/uniform_sampling.h>
#include <pcl/filters/voxel_grid.h>

int main()
{
    //open las file
    std::ifstream ifs("E:/temp/in/Tile_1321222320002302112.las", std::ios::in | std::ios::binary);
    liblas::ReaderFactory f;
    liblas::Reader reader = f.CreateWithStream(ifs);

    //read las head
    liblas::Header const& header = reader.GetHeader();
    int nbPoints = header.GetPointRecordsCount();

    //转换为pcl格式
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr in_cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
    while (reader.ReadNextPoint())
    {

        //坐标信息
        double x = reader.GetPoint().GetX();
        double y = reader.GetPoint().GetY();
        double z = reader.GetPoint().GetZ();

        //颜色信息
        uint16_t r1 = reader.GetPoint().GetColor().GetRed();
        uint16_t g1 = reader.GetPoint().GetColor().GetGreen();
        uint16_t b1 = reader.GetPoint().GetColor().GetBlue();
        uint32_t r2 = ceil(((float)r1 / 65536)*(float)256);
        uint32_t g2 = ceil(((float)g1 / 65536)*(float)256);
        uint32_t b2 = ceil(((float)b1 / 65536)*(float)256);
        uint32_t rgb = ((int)r2 << 16 | (int)g2 << 8 | (int)b2);
        pcl::PointXYZRGB thept;
        thept.x = x;
        thept.y = y;
        thept.z = z;
        thept.rgb = rgb;
        in_cloud->push_back(thept);

    }

    //采样
    //pcl::UniformSampling<pcl::PointXYZRGB> filter;
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr filteredCloud(new pcl::PointCloud<pcl::PointXYZRGB>);
    
    //均匀
    //filter.setInputCloud(in_cloud);
    //filter.setRadiusSearch(0.1f);
    //filter.filter(*filteredCloud);

    pcl::VoxelGrid<pcl::PointXYZRGB> filter;
    filter.setInputCloud(in_cloud);
    filter.setLeafSize(0.1f,0.1f,0.1f);
    filter.filter(*filteredCloud);
    int out_p_n = filteredCloud->size();

    //写入las文件
    std::string save_path = "E:/temp/out/";
    std::string name = "Tile_1321222320002302112.las";

    double minPt[3] = { 9999999, 9999999, 9999999 };
    double maxPt[3] = { 0, 0, 0 };

    std::ofstream ofs = std::ofstream(save_path + name, std::ios::out | std::ios::binary);
    //设置文件头、点数、格式、缩放因子、偏移量
    liblas::Header f_header;
    f_header.SetVersionMajor(1);
    f_header.SetVersionMinor(2);
    f_header.SetMin(minPt[0], minPt[1], minPt[2]);
    f_header.SetMax(maxPt[0], maxPt[1], maxPt[2]);
    f_header.SetDataFormatId(liblas::PointFormatName::ePointFormat3);
    f_header.SetOffset(0, 0, 0);
    f_header.SetScale(0.001, 0.001, 0.001);
    f_header.SetPointRecordsCount(out_p_n);
    liblas::Writer writer(ofs,f_header);
    liblas::Point point(&f_header);

    for (size_t i = 0; i < filteredCloud->size(); ++i)
    {
        double x = filteredCloud->points[i].x;
        double y = filteredCloud->points[i].y;
        double z = filteredCloud->points[i].z;
        point.SetX(x);
        point.SetY(y);
        point.SetZ(z);
        uint32_t r = (uint32_t)filteredCloud->points[i].r;
        uint32_t g = (uint32_t)filteredCloud->points[i].g;
        uint32_t b = (uint32_t)filteredCloud->points[i].b;
        liblas::Color pointColor(r, g, b);
        point.SetColor(pointColor);
        writer.WritePoint(point);
    }

    writer.SetHeader(f_header);
    ofs.flush();
    ofs.close();

    return EXIT_SUCCESS;

}
4

0 回答 0