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) { //-31370.820999145508 -19133.3065032959 46696.00296020508 169.0 173.0 172.0 String[] line_strs = lineStr.split(" "); double x = Double.parseDouble(line_strs[0])*0.001; double y = Double.parseDouble(line_strs[1])*0.001; double z = Double.parseDouble(line_strs[2])*0.001; String newLineStr = x+" "+y+" "+z+" "+line_strs[3]+" "+line_strs[4]+" "+line_strs[5]; bufferedWriterObj.write(newLineStr+"\n"); } bufferedWriterObj.flush(); bufferedWriterObj.close(); fileWriterObj.close(); bufferedReaderObj.close(); fileReaderObj.close(); } }
########################
QQ 3087438119