Created
February 11, 2019 11:46
-
-
Save HTLife/e8f1c4ff1737710e34258ef965b48344 to your computer and use it in GitHub Desktop.
Convert KITTI velodyne bin to open3d pcd
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
import numpy as np | |
import struct | |
from open3d import * | |
def convert_kitti_bin_to_pcd(binFilePath): | |
size_float = 4 | |
list_pcd = [] | |
with open(binFilePath, "rb") as f: | |
byte = f.read(size_float * 4) | |
while byte: | |
x, y, z, intensity = struct.unpack("ffff", byte) | |
list_pcd.append([x, y, z]) | |
byte = f.read(size_float * 4) | |
np_pcd = np.asarray(list_pcd) | |
pcd = PointCloud() | |
pcd.points = Vector3dVector(np_pcd) | |
return pcd |
import numpy as np
import struct
from open3d import *
def convert_kitti_bin_to_pcd(binFilePath):
size_float = 4
list_pcd = []
with open(binFilePath, "rb") as f:
byte = f.read(size_float * 4)
while byte:
x, y, z, intensity = struct.unpack("ffff", byte)
list_pcd.append([x, y, z])
byte = f.read(size_float * 4)
np_pcd = np.asarray(list_pcd)
pcd = open3d.geometry.PointCloud()
pcd.points = open3d.utility.Vector3dVector(np_pcd)
return pcd
# source
bin_file = '1644609772_916356000.bin'
# convert
pcd_ = convert_kitti_bin_to_pcd(bin_file)
# show
print(pcd_)
print(np.asarray(pcd_.points))
open3d.visualization.draw_geometries([pcd_])
# save
open3d.io.write_point_cloud('1644609772_916356000.pcd', pcd_, write_ascii=False, compressed=False, print_progress=False)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I would like to use this piece of code but i get:
NameError Traceback (most recent call last)
in
----> 1 convert_kitti_bin_to_pcd(path)
in convert_kitti_bin_to_pcd(binFilePath)
13 byte = f.read(size_float * 4)
14 np_pcd = np.asarray(list_pcd)
---> 15 pcd = PointCloud()
16 pcd.points = Vector3dVector(np_pcd)
17 return pcd
NameError: name 'PointCloud' is not defined
What import am I missing? Thank you!