Closed pavankumarbn closed 3 years ago
Hi @pavankumarbn,
Could you paste in the terminal logs of how you're running it, and the subsequent error? Thanks!
Hi, @kairenw, Thanks for your response. Please find the complete code below:
import os
import numpy as np
from ouster import client
from ouster import pcap
from itertools import islice
pcap_path = 'sample.pcap'
metadata_path = 'sample.json'
csv_dir = 'test_csv/'
csv_base = '/test'
csv_ext = '.gz'
with open(metadata_path, 'r') as f:
metadata = client.SensorInfo(f.read()) source = pcap.Pcap(pcap_path, metadata) xyzlut = client.XYZLut(metadata) scans = iter(client.Scans(source)) num = 5
if num: scans = islice(scans, num) for idx, scan in enumerate(scans):
col_timestamps = scan.header(client.ColHeader.TIMESTAMP)
timestamps = np.tile(col_timestamps, (scan.h, 1))
fields_values = [scan.field(ch) for ch in client.ChanField]
xyz = (xyzlut(scan) * 1000).astype(np.int64)
frame = np.dstack((timestamps, *fields_values, xyz))
frame = client.destagger(metadata, frame)
csv_path = os.path.join(csv_dir, f'{csv_base}_{idx:06d}.{csv_ext}')
print(f'write frame #{idx}, to file: {csv_path}')
header = '\n'.join([f'frame num: {idx}', field_names])
np.savetxt(csv_path,frame.reshape(-1, frame.shape[2]),fmt=field_fmts,delimiter=',',header=header)
When I run this code it is giving following error:
Traceback (most recent call last): File "pcaptocsv.py", line 44, in <module> header = '\n'.join([f'frame num: {idx}', field_names]) NameError: name 'field_names' is not defined
Hey @pavankumarbn,
I think you just need to define field_names
and field_fmts
. You probably just want these two lines from the pcap-to-csv example:
field_names = 'TIMESTAMP (ns), RANGE (mm), SIGNAL, NEAR_IR, REFLECTIVITY, X (mm), Y (mm), Z (mm)'
field_fmts = ['%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d']
I think the indentations got lost when you pasted in your code, but you probably want to do it up top before any loops.
Hi @kairenw, Thanks a lot for your kind help and support. I added these two lines, it is working perfectly fine now. I have another question, is it possible to convert the ouster recorded .pcap file .bag (ROS format). If yes, please guide me on how to do it?
Hi @pavankumarbn,
Glad that worked out for you.
We don't currently have code that converts the Ouster record .pcap file to .bag. Since this is a duplicate issue to ouster-lidar/ouster-ros#7, I will close this issue now.
Thanks!
Hi @kairenw, Sure I will go through it. Once again many thanks for your timely help.
Hello All,
I am trying to convert ouster recorded .pcap data to CSV format. When I try to run the linked code https://static.ouster.dev/sdk-docs/api.html#ouster.sdk.examples.pcap.pcap_to_csv it is throwing
header = '\n'.join([f'frame num: {idx}', field_names]) NameError: name 'field_names' is not defined
. Please help me with how to fix this issue?Thanks, Pavan