给pcd添加头
给pcd添加头
package com.vfsd.core; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class ReadPCDAndWritePCD { private static String headerStr = "# .PCD v0.7 - Point Cloud Data file format\r\n" + "VERSION 0.7\r\n" + "FIELDS x y z rgb\r\n" + "SIZE 4 4 4 4\r\n" + "TYPE F F F U\r\n" + "COUNT 1 1 1 1\r\n" + "WIDTH 1280\r\n" + "HEIGHT 720\r\n" + "VIEWPOINT 0 0 0 1 0 0 0\r\n" + "POINTS 921600\r\n" + "DATA ascii"; public static void main(String[] args) { String pcdPath = "F:\\PytorchProject\\yolov5-master_2022040401\\data\\out_2022040519"; String outputPath ="G:\\PCL_data\\2022040502"; listAllPCD( pcdPath, outputPath); } public static void listAllPCD(String pcdPath,String outputPath) { File dirFile = new File(pcdPath); if(dirFile.isDirectory()) { File[] listFiles = dirFile.listFiles(); for(File indxFile:listFiles) { String pcdName = indxFile.getName(); if(!pcdName.endsWith(".txt")) { continue; } System.out.println(pcdName); String outputFileName = outputPath + File.separator+pcdName.replace(".txt", ".pcd"); File newFile = new File(outputFileName); try { readAndWriteData( indxFile, newFile); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } public static void readAndWriteData(File oldFile,File newFile) throws IOException { FileReader fileReaderObj = new FileReader(oldFile); BufferedReader bufferedReaderObj = new BufferedReader(fileReaderObj); FileWriter fileWriterObj = new FileWriter(newFile); BufferedWriter bufferedWriterObj = new BufferedWriter(fileWriterObj); //写入头文件 bufferedWriterObj.write(headerStr+"\n"); String lineStr = ""; while((lineStr=bufferedReaderObj.readLine())!=null) { bufferedWriterObj.write(lineStr+"\n"); } bufferedWriterObj.flush(); bufferedWriterObj.close(); fileWriterObj.close(); bufferedReaderObj.close(); fileReaderObj.close(); } }
################
QQ 3087438119