Last active
June 6, 2020 07:55
-
-
Save danielkochdakitec/a7f68de0aff07ebf85732f4830e7a229 to your computer and use it in GitHub Desktop.
Convert a PTS to a PCD file using Python line-by-line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputFile = open("result_input.pts", "r") # Input-file | |
outputFile = open("result_output.pcd", "w") # Output-file | |
length = int(inputFile.readline()) # First line is the length | |
outputFile.write("VERSION .7\nFIELDS x y z rgb\nSIZE 4 4 4 4\nTYPE F F F F\nCOUNT 1 1 1 1\nWIDTH {}\nHEIGHT 1\nVIEWPOINT 0 0 0 1 0 0 0\nPOINTS {}\nDATA ascii\n".format(length, length)) # Sets the header of pcd in a specific format, see more on http://pointclouds.org/documentation/tutorials/pcd_file_format.php | |
currentLinePosition = 0 | |
for line in inputFile: | |
currentLinePosition = currentLinePosition + 1 | |
if(currentLinePosition % 100000 == 0): | |
print "Current file position: " + str(currentLinePosition) | |
currentLine = line.rstrip().split(" ") | |
outputFile.write(" ".join([ | |
currentLine[0], # x-value | |
currentLine[1], # y-value | |
currentLine[2], # z-value | |
"{:e}".format((int(currentLine[4])<<16) + (int(currentLine[5])<<8) + int(currentLine[6])) # rgb value renderd in scientific format | |
]) + "\n") | |
inputFile.close() | |
outputFile.close() | |
print "All done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 | |
-11.3969 -8.65372 1.06098 233 232 236 235 | |
-11.40162 -8.52385 0.01862 227 231 233 228 | |
-12.9457 -8.30231 1.50229 211 208 218 217 | |
-11.39186 -8.46765 1.34963 228 225 231 229 | |
-12.74268 -9.94807 1.51049 146 149 152 141 | |
-11.90631 -9.97656 1.51388 119 121 127 117 | |
-13.0189 -8.30898 1.50209 212 208 220 220 | |
-12.94583 -8.2678 1.50147 211 205 217 217 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VERSION .7 | |
FIELDS x y z rgb | |
SIZE 4 4 4 4 | |
TYPE F F F F | |
COUNT 1 1 1 1 | |
WIDTH 8 | |
HEIGHT 1 | |
VIEWPOINT 0 0 0 1 0 0 0 | |
POINTS 8 | |
DATA ascii | |
-11.3969 -8.65372 1.06098 1.526500e+07 | |
-11.40162 -8.52385 0.01862 1.519869e+07 | |
-12.9457 -8.30231 1.50229 1.368751e+07 | |
-11.39186 -8.46765 1.34963 1.480496e+07 | |
-12.74268 -9.94807 1.51049 9.803917e+06 | |
-11.90631 -9.97656 1.51388 7.962485e+06 | |
-13.0189 -8.30898 1.50209 1.368803e+07 | |
-12.94583 -8.2678 1.50147 1.349065e+07 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment