运行MULLS代码出现的问题(三)

39 篇文章 1 订阅
21 篇文章 2 订阅

在这里夸夸我亲爱的小伙伴,帮助我找到了路径问题!!!

最近遇到个世界难题,用MULLS程序自带的txt2pcd代码运行出来原本五万个点却只有四万个点,打开后点数量还不一样了

在这里附上源程序的代码,我觉得很简短,不知道是不是做了滤波什么的,但是形状数量都改变了,很奇怪

#include "dataio.hpp"
#include "utility.hpp"

#include <iostream>
#include <fstream>

using namespace std;
using namespace lo;

// Brief: Do the batch txt2pcd transformation

int main(int argc, char **argv)
{
    // The file to read from.
    string infile = argv[1];

    // The file to output to.
    string outfile = argv[2];

    std::cout << "Transform begin" << std::endl;

    // Load point cloud
    fstream input(infile.c_str(), ios::in | ios::binary);
    if (!input.good())
    {
        cerr << "Could not read file: " << infile << endl;
        exit(EXIT_FAILURE);
    }
    input.seekg(0, ios::beg);

    pcTPtr pointCloud(new pcT);

    DataIo<Point_T> dataio;
    dataio.read_txt_file(infile, pointCloud);

    cout << "Read txt file from [" << infile << "]: " << pointCloud->points.size() << " points, writing to [" << outfile << "]" << endl;

    dataio.write_pcd_file(outfile, pointCloud);

    std::cout << "Transform done" << std::endl;
}

我觉得他的批量处理代码很好,需要写一个sh文件
.sh文件内容如下

#!/bin/sh

infolder=demo_data
mkdir ${infolder}/pcd
for file in ${infolder}/txt/*.txt
do 
	./bin/txt2pcd $file ${infolder}/pcd/`basename $file .txt`.pcd
done

于是,我使用pcl方法修改了.cpp文件,一定注意路径!!!
运行的时候一定在数据所在的位置输入build/XXX
如果你直接在生成的结果里./XXX    会报错!!!

感谢我亲爱的小伙伴找到了我的问题,代码没问题,路径和最后运行的文件夹出现了错误!!!!

点数与txt文件对应正确
改成批量处理的代码如下

#include <iostream>
#include <fstream>
using namespace std;
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <Eigen/Geometry> 
#include <boost/format.hpp>  // for formating strings
#include <pcl/point_types.h> 
#include <pcl/io/pcd_io.h> 
#include <pcl/visualization/pcl_visualizer.h>

int main( int argc, char** argv )
{
    
    // The file to read from.
    string infile = argv[1];

    // The file to output to.
    string outfile = argv[2];

    std::cout << "Transform begin" << std::endl;

    // Load point cloud
    fstream input(infile.c_str(), ios::in | ios::binary);
    if (!input.good())
    {
        cerr << "Could not read file: " << infile << endl;
        exit(EXIT_FAILURE);
    }
    pcl::PointCloud<pcl::PointXYZ> cloud;
    pcl::PCDWriter writer;
    pcl::PointXYZ pclPnt;
    while(!input.eof())
    {
        input>>pclPnt.x>>pclPnt.y>>pclPnt.z;
        cloud.push_back(pclPnt);
    }
    input.close();
    writer.write(outfile,cloud);
   

    cout << "Read txt file from [" << infile << "]: " << cloud.points.size() << " points, writing to [" << outfile << "]" << endl;

    std::cout << "Transform done" << std::endl;


   
   
}

sh 文件不变!!!成功运行!!!

要点:最后运行成果文件的时候最好在根目录下进行,不然会因为找不到输入文件报错!!!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Laney_Midory

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

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

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

打赏作者

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

抵扣说明:

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

余额充值