最近在学习pointnet,需要将点云的pcd文件名写入txt文件,然后需要会读取txt文件里的pcd文件制作dhf5文件,还需要将lable写入txt文件。
具体代码如下:
#include <fstream>
#include <iostream>
#include <string>
#include <boost/format.hpp>
int write_string_to_file_append(const std::string & file_string, const std::string str )
{
std::ofstream OsWrite(file_string,std::ofstream::app);
OsWrite<<str;
OsWrite<<std::endl;
OsWrite.close();
return 0;
}
int main()
{
boost::format f;
std::string filename,lable0,lable1;
int count = 0;
while(1)
{
f = boost::format("%s%d%s") %"raw_data/test_pcd" %count %".pcd";
filename = f.str();
lable0 = "0";
lable1 = "1";
write_string_to_file_append(std::string("pcd_names_file1.txt"),filename);
if(count < 249)
{
write_string_to_file_append(std::string("labels_file1.txt"),lable0);
}
else
{
write_string_to_file_append(std::string("labels_file1.txt"),lable1);
}
count ++;
if(count > 708)
{
break;
}
}
return 0;
}
编译方法如下即Makefile文件;
CC = g++
CFLAGS =
#CC = aarch64-linux-gnu-g++
#CFLAGS = -L../../lib -lTTF_API -lvoxel -lusb-1.0 -std=c++11 -lti3dtof -lgomp -lc
STRIP = strip
INC =
all :
$(CC) -c Read_write.cpp $(INC) $(CFLAGS)
$(CC) -o Read_write Read_write.o $(INC) $(CFLAGS)
rm Read_write.o
clean :
rm -rf Read_write
这是在linux下进行运行的。