Squashed commit of the following:
commit 263e56f9ec8d94a984bc45588acb662c590e6e3a
Author: wu_xinjun <bent20140204@outlook.com>
Date: Tue Mar 15 14:51:34 2022 +0800
process mutiFrame bin file
| | |
| | | "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" |
| | | }, |
| | |
| | | "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" |
| | | } |
| | |
| | | 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% |
| | |
| | | |
| | | 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: |
| | | """ |
| | | 解析完整的一帧数据,数据包括数据头,数据体,数据尾,返回点云数组 |
| | | 解析完整的帧数据,数据包括数据头,数据体,数据尾,返回点云数组 |
| | | """ |
| | | 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 [] |
| | | 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 |
| | |
| | | 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) |
| | |
| | | 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!") |
| | | 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!") |
| | |
| | | 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 = [] |
| | |
| | | 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 |
| | | |