wu_xinjun
2022-05-13 13530d0ad2c32608d0b46a5c16ad4ac0c25b59f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
from tkinter import Frame
from .components import *
from .constants import *
from ctypes import sizeof, string_at
 
perDetectionBytes = 8
perTrackerBytes = 32
 
class MicroWaveParser:
    @classmethod
    def ParserFrame(cls, buffer: bytes) -> list:
        """
        解析完整的帧数据,数据包括数据头,数据体,数据尾,返回点云数组
        """
        buffer_size = len(buffer)
        frame_start = 0
        frame_end = 0
        frame_id = 0
 
        ply_data_list = []
 
        while frame_start < buffer_size:
            # process the current frame
            header = HeaderBlock(buffer[frame_start:frame_start+sizeof(HeaderBlock)])
            if HEADER_MAGIC == string_at(header.Magic, 8):
                numsDetection = header.NumberOfDetection
                numsTracker = header.NumberOfTrack
 
                # get the end point of the current frame
                frame_end = frame_start + \
                            sizeof(HeaderBlock) + \
                            numsDetection * perDetectionBytes + \
                            numsTracker * perTrackerBytes + \
                            sizeof(FooterBlock)
 
                if frame_end <= buffer_size:
                    # get the frame data and footer data
                    frame = buffer[frame_start:frame_end]
                    footer = FooterBlock(frame[-sizeof(FooterBlock):])
                    # get the cloud point data
                    point_cloud = []
 
                    for i in range(numsDetection):
 
                        point_data = frame[i * 8 + sizeof(HeaderBlock): (i + 1) * 8 + sizeof(HeaderBlock)]
                        detection = DetectionBlock(header, footer, point_data)
                        point = [detection.X, detection.Y, detection.Z]
                        point_cloud.append(point)
 
                    # append the point cloud data to the list
                    ply_data_list.append([frame_id, header.FrameNumber, point_cloud])
 
                # update the parameters for next frame in the while loop
                frame_id += 1
                frame_start = frame_end
            else:
                raise ValueError("wrong header magic code for microwave data")
                
        return ply_data_list