From 4033aede52133f254f320838d2339ca3bfcb77e9 Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期二, 15 三月 2022 14:53:11 +0800
Subject: [PATCH] Squashed commit of the following:
---
src/microwave/parsers.py | 63 +++++++++++++++++++++++++------
1 files changed, 50 insertions(+), 13 deletions(-)
diff --git a/src/microwave/parsers.py b/src/microwave/parsers.py
index 97c0b07..ee14151 100644
--- a/src/microwave/parsers.py
+++ b/src/microwave/parsers.py
@@ -1,23 +1,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:
"""
- 瑙f瀽瀹屾暣鐨勪竴甯ф暟鎹紝鏁版嵁鍖呮嫭鏁版嵁澶达紝鏁版嵁浣擄紝鏁版嵁灏撅紝杩斿洖鐐逛簯鏁扮粍
+ 瑙f瀽瀹屾暣鐨勫抚鏁版嵁锛屾暟鎹寘鎷暟鎹ご锛屾暟鎹綋锛屾暟鎹熬锛岃繑鍥炵偣浜戞暟缁�
"""
- header = HeaderBlock(buffer[:sizeof(HeaderBlock)])
- if HEADER_MAGIC == string_at(header.Magic, 8):
- footer = FooterBlock(buffer[-sizeof(FooterBlock):])
- point_cloud = []
- for i in range(header.NumberOfDetection):
- detection = DetectionBlock(header, footer, buffer[i * 8 + sizeof(HeaderBlock): (i + 1) * 8 + sizeof(HeaderBlock)])
- point = (detection.X, detection.Y, detection.Z)
- point_cloud.append(point)
- return point_cloud
- else:
- return []
\ No newline at end of file
+ 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
\ No newline at end of file
--
Gitblit v1.9.1