官方的sdk没有明确的给出清晰完整的数据解析程序,只好自己写一个,如果对您有用希望给一个免费的赞,感谢~
安装SDK:
参考 https://static.ouster.dev/sdk-docs/installation.html
转存TXT程序
from ouster import client
from ouster import pcap
from itertools import islice
import numpy as np
dual = False
start_index = 0
num_scans = 100
metadata_path = '20240420_1336_OS-2-64-U02_992032000485.json'
pcap_path = '20240420_1336_OS-2-64-U02_992032000485.pcap'
with open(metadata_path, 'r') as f:
metadata = client.SensorInfo(f.read())
print(metadata)
source = pcap.Pcap(pcap_path, metadata)
# precompute xyzlut to save computation in a loop
xyzlut = client.XYZLut(metadata)
# create an iterator of LidarScans from pcap and bound it if num is specified
scans = iter(client.Scans(source))
# if num_scans is None
scans = islice(scans, start_index, start_index + num_scans)
row_layer = np.fromfunction(lambda i, j: i,
(metadata.format.pixels_per_column,
metadata.format.columns_per_frame), dtype=int)
column_layer = np.fromfunction(lambda i, j: j,
(metadata.format.pixels_per_column,
metadata.format.columns_per_frame), dtype=int)
column_layer_staggered = client.destagger(metadata, column_layer,
inverse=True)
idx = None
for idx, scan in enumerate(scans):
# initialize the field names for csv header
# if not field_names or not field_fmts:
# field_names, field_fmts = get_fields_info(scan)
# copy per-column timestamps and measurement_ids for each beam
timestamps = np.tile(scan.timestamp, (scan.h, 1))
measurement_ids = np.tile(scan.measurement_id, (scan.h, 1))
# grab channel data
fields_values = [scan.field(ch) for ch in scan.fields]
frame = np.dstack((timestamps, row_layer, column_layer_staggered,
measurement_ids, *fields_values))
# output points in "image" vs. staggered order
frame = client.destagger(metadata, frame)
# destagger XYZ separately since it has a different type
xyz = xyzlut(scan.field(client.ChanField.RANGE))
xyz_destaggered = client.destagger(metadata, xyz)
if dual:
xyz2 = xyzlut(scan.field(client.ChanField.RANGE2))
xyz2_destaggered = client.destagger(metadata, xyz2)
# get all data as one H x W x num fields int64 array for savetxt()
frame = np.dstack(tuple(map(lambda x: x.astype(object),
(frame, xyz_destaggered, xyz2_destaggered))))
else:
# get all data as one H x W x num fields int64 array for savetxt()
frame = np.dstack(tuple(map(lambda x: x.astype(object),
(frame, xyz_destaggered))))
frame_colmajor = np.swapaxes(frame, 0, 1)
# write csv out to file
csv_path = 'Data1/' + str(idx)+'.txt'
print(f'write frame index #{idx + start_index}, to file: {csv_path}')
np.savetxt(csv_path,frame_colmajor.reshape(-1, frame.shape[2]) , fmt='%f', delimiter=' ')
# header = '\n'.join([f'frame num: {idx}', field_names])
# np.savetxt(csv_path,
# frame_colmajor.reshape(-1, frame.shape[2]),
# fmt=field_fmts,
# delimiter=',',
# header=header)
本文详细描述了如何在没有官方完整数据解析程序的情况下,安装OusterSDK,处理PCAP文件中的Lidar数据,将其转换为CSV格式,包括预计算、数据提取和文件输出的过程。
1542

被折叠的 条评论
为什么被折叠?



