主要使用了 dpkt 解析的pcap 文件,然后按照 velodyne 的协议解析UDP数据,话不多说,直接上代码吧
# -*- coding: UTF-8 -*-
import dpkt
import collections # 有序字典需要的模块
import time
import numpy as np
import struct
# 如果安装了pcl , 可以使用它来进行可视化
# import pcl.pcl_visualization
# viewer = pcl.pcl_visualization.PCLVisualizering()
# viewer.SetBackgroundColor(0, 0, 0)
# viewer.AddCoordinateSystem()
# viewer.InitCameraParameters()
# vlp 16 的参数
DISTANCE_RESOLUTION = 0.002 # 距离数值分辨率 转换为单位米
udp_package_num = 1
line_per_udp = 12 # 每个UDP 有多少列
point_per_udp_line = 32 # 每个UDP 的每列包含有多少个点
point_num_per_udp = point_per_udp_line * line_per_udp # 32*12=384
thetas_lines = [-15, 1, -13, 3, -11, 5, -9, 7, -7, 9, -5, 11, -3, 13, -1, 15]
thetas_point = thetas_lines * 2 * line_per_udp * udp_package_num
thetas_point = np.radians(thetas_point)
thetas_point_cos = np.cos(thetas_point)
thetas_point_sin = np.sin(thetas_point)
data_fmt = '<' + (('H' + 'H' + 'HB' * point_per_udp_line) * line_per_udp + 'IH') * udp_package_num
base_range = np.array(range(2, point_per_udp_line*2+1, 2)) # 32, 距离值的基础索引
angle_base_range = np.array([1])
d_range =