Python-VTK点云实时显示

时间:2019-06-10 09:42:04

标签: python sensor vtk lidar

我从vlp 16激光雷达传感器接收到传感器数据。然后将原始数据转换为x,y,z(分辨率)数据。 我想实时显示3d数据。 我找到了一些工具,例如vtk,pptk等,并显示存储的数据。 但我无法实时显示这些内容。 我不知道该怎么办。我找不到详细信息。 您能给我一些信息,建议或例子吗? 谢谢。

我实时尝试了pptk。但每次都会打开新窗口。

import socket
import numpy as np
from multiprocessing import Process, Queue
import time
import traceback
import struct
import pptk


HOST = "192.168.1.201"
PORT = 2368

LASER_ANGLES = [-15, 1, -13, 3, -11, 5, -9, 7, -7, 9, -5, 11, -3, 13, -1, 15]
NUM_LASERS = 16

EXPECTED_PACKET_TIME = 0.001327  # valid only in "the strongest return mode"
EXPECTED_SCAN_DURATION = 0.1
DISTANCE_RESOLUTION = 0.002
ROTATION_RESOLUTION = 0.01
ROTATION_MAX_UNITS = 36000

soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
soc.bind(('', PORT))


def calc(dis, azimuth, laser_id, timestamp):
    R = dis * DISTANCE_RESOLUTION
    omega = LASER_ANGLES[laser_id] * np.pi / 180.0
    alpha = azimuth / 100.0 * np.pi / 180.0
    X = R * np.cos(omega) * np.sin(alpha)
    Y = R * np.cos(omega) * np.cos(alpha)
    Z = R * np.sin(omega)
    return [X, Y, Z]

while True:
    data, addr = soc.recvfrom(2000)

    prev_azimuth = None
    ts = time.time()
    timestamp, factory = struct.unpack_from("<IH", data, offset=1200)
    seq_index = 0
    for offset in range(0, 1200, 100):
        flag, azimuth = struct.unpack_from("<HH", data, 0)

        for step in range(2):
            seq_index += 1
            azimuth += step
            azimuth %= ROTATION_MAX_UNITS

            if prev_azimuth is not None and azimuth < prev_azimuth:
                points = []
            prev_azimuth = azimuth
            arr = struct.unpack_from('<' + "HB" * 16, data, offset + 4 + step * 48)
            for i in range(NUM_LASERS):
                time_offset = (55.296 * seq_index + 2.304 * i) / 1000000.0
                if arr[i * 2] != 0:
                    points.append(calc(arr[i * 2], azimuth, i, timestamp + time_offset))
                    print(calc(arr[i * 2], azimuth, i, timestamp + time_offset))
    points_np = np.array(points)

0 个答案:

没有答案