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/utils/bin2ply.py | 49 +++++++++-------
src/microwave/parsers.py | 63 ++++++++++++++++----
.vscode/launch.json | 4
TEST_bin2ply.bat | 4 +
src/utils/tools.py | 8 +-
5 files changed, 88 insertions(+), 40 deletions(-)
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 5a99968..1e12093 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -93,7 +93,7 @@
"python": "${workspaceFolder}/env/aerial_deploy/python.exe",
"program": "${workspaceFolder}/src/utils/udp2bin.py",
"args": [
- "./Manual_Microwave/pod1-2022-02-21-15-34-45/"
+ "./src/microwave/demo/demoData"
],
"console": "integratedTerminal"
},
@@ -104,7 +104,7 @@
"python": "${workspaceFolder}/env/aerial_deploy/python.exe",
"program": "${workspaceFolder}/src/utils/bin2ply.py",
"args": [
- "./Manual_Microwave/pod1-2022-02-21-15-34-45/"
+ "T:/Data/projects/huaneng/00_Docs/mutiFrameBin"
],
"console": "integratedTerminal"
}
diff --git a/TEST_bin2ply.bat b/TEST_bin2ply.bat
index c5e9f1b..af22ebd 100644
--- a/TEST_bin2ply.bat
+++ b/TEST_bin2ply.bat
@@ -14,7 +14,9 @@
cd %~dp0
echo change to path: %cd%
-set BINfolder=./Manual_Microwave_test/pod1-2022-02-21-15-34-45/
+echo [the folder example]: ./slamdata/
+set /p BINfolder=Please input the bin data folder:
+
@REM ---------------Usage: bin2ply.py [BINfolder]
%aerialpython% ./src/utils/bin2ply.py %BINfolder%
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
diff --git a/src/utils/bin2ply.py b/src/utils/bin2ply.py
index 38b12ba..90cb889 100644
--- a/src/utils/bin2ply.py
+++ b/src/utils/bin2ply.py
@@ -21,8 +21,8 @@
try:
BINfolder = str(sys.argv[1])
# example pod1-2022-02-21-13-25-03_packet125.udp --> 125
- sort_lambda = lambda x:int(x.split('.')[0])
- bin_files = file_fliter(BINfolder,'bin', sort_lambda)
+ # sort_lambda = lambda x:int(x.split('.')[0])
+ bin_files = file_fliter(BINfolder,'bin')
except Exception as e:
print(e)
@@ -31,24 +31,31 @@
for file in bin_files:
filename = file
- (fn, ext) = os.path.splitext(filename)
+ # (fn, ext) = os.path.splitext(filename)
with open(os.path.join(BINfolder,file), "rb") as bin_file:
buf = bin_file.read()
- point_cloud = MicroWaveParser.ParserFrame(buf)
- with open(os.path.join(BINfolder,fn +".ply"), "w") as f:
- f.write("ply\n")
- f.write("format ascii 1.0\n")
- f.write("comment MicroWave2Ply generated\n")
- f.write("element vertex %d\n" % len(point_cloud))
- f.write("property float x\n")
- f.write("property float y\n")
- f.write("property float z\n")
- f.write("element face 0\n")
- f.write("property list uchar int vertex_indices\n")
- f.write("end_header\n")
- n_p = 0
- for p in point_cloud:
- x, y, z = p
- f.write("{:.5f} {:.5f} {:.5f}\n".format(x, y, z))
- n_p += 1
- print(time.asctime(),f"Frame {fn}.ply have been saved with {n_p} points!")
\ No newline at end of file
+ buf_data = MicroWaveParser.ParserFrame(buf)
+
+
+ for frame in buf_data:
+ Frame_id = frame[0]
+ FrameNumber = frame[1]
+ point_cloud = frame[2]
+ if len(point_cloud) != 0 :
+ with open(os.path.join(BINfolder,str(FrameNumber) +".ply"), "w") as f:
+ f.write("ply\n")
+ f.write("format ascii 1.0\n")
+ f.write("comment MicroWave2Ply generated\n")
+ f.write("element vertex %d\n" % len(point_cloud))
+ f.write("property float x\n")
+ f.write("property float y\n")
+ f.write("property float z\n")
+ f.write("element face 0\n")
+ f.write("property list uchar int vertex_indices\n")
+ f.write("end_header\n")
+ n_p = 0
+ for p in point_cloud:
+ x, y, z = p
+ f.write("{:.5f} {:.5f} {:.5f}\n".format(x, y, z))
+ n_p += 1
+ print(time.asctime(),f"File {file} Frame {FrameNumber}.ply have been saved with {n_p} points!")
\ No newline at end of file
diff --git a/src/utils/tools.py b/src/utils/tools.py
index ee2f8de..3db661f 100644
--- a/src/utils/tools.py
+++ b/src/utils/tools.py
@@ -2,7 +2,7 @@
import numpy as np
import time
-def file_fliter(folder:str, file_ext:str, sort_format):
+def file_fliter(folder:str, file_ext:str, sort_format = None):
files_List = os.listdir(folder)
target_files = []
@@ -11,8 +11,10 @@
for file in files_List:
if file.split('.')[-1] == file_ext:
target_files.append(file)
- # sort the list by the sort_format
- target_files.sort(key=sort_format)
+
+ if sort_format is not None:
+ # sort the list by the sort_format
+ target_files.sort(key=sort_format)
return target_files
--
Gitblit v1.9.1