From 74e72304b0f38fddbfe3d12a70d0c9a09d25e85f Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期一, 21 三月 2022 12:36:09 +0800
Subject: [PATCH] auto slam

---
 src/utils/bin2ply.py |   46 +++++++++++++++++++++++++---------------------
 1 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/src/utils/bin2ply.py b/src/utils/bin2ply.py
index 90cb889..085d392 100644
--- a/src/utils/bin2ply.py
+++ b/src/utils/bin2ply.py
@@ -8,31 +8,16 @@
 sys.path.insert(0, src_path)
 
 from microwave.parsers import MicroWaveParser
-from tools import file_fliter
+from .tools import file_fliter
 
-if __name__ == "__main__":
-    def help():
-        print("Usage: bin2ply.py [BINfolder]")
-        print("EXAMPLE: BIN2ply.py ./manual_ply/pod1-2012-12-12-12-12-12/")
-        exit(1)
+def bin2ply_tool(folder):
+    bin_files = file_fliter(folder,'bin')
 
-    if len(sys.argv) != 2:
-        help()
-    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')
-
-    except Exception as e:
-        print(e)
-        help()
-    
     for file in bin_files:
 
         filename = file
         # (fn, ext) = os.path.splitext(filename)
-        with open(os.path.join(BINfolder,file), "rb") as bin_file:
+        with open(os.path.join(folder,file), "rb") as bin_file:
             buf = bin_file.read()
             buf_data = MicroWaveParser.ParserFrame(buf)
 
@@ -42,7 +27,7 @@
                 FrameNumber = frame[1]
                 point_cloud = frame[2]
                 if len(point_cloud) != 0 :
-                    with open(os.path.join(BINfolder,str(FrameNumber) +".ply"), "w") as f:
+                    with open(os.path.join(folder,str(FrameNumber) +".ply"), "w") as f:
                         f.write("ply\n")
                         f.write("format ascii 1.0\n")
                         f.write("comment MicroWave2Ply generated\n")
@@ -58,4 +43,23 @@
                             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
+                        print(time.asctime(),f"File {file} Frame {FrameNumber}.ply have been saved with {n_p} points!")
+
+
+
+if __name__ == "__main__":
+    def help():
+        print("Usage: bin2ply.py [BINfolder]")
+        print("EXAMPLE: BIN2ply.py ./manual_ply/pod1-2012-12-12-12-12-12/")
+        exit(1)
+
+    if len(sys.argv) != 2:
+        help()
+    try:
+        BINfolder = str(sys.argv[1])
+
+    except Exception as e:
+        print(e)
+        help()
+    
+    bin2ply_tool(BINfolder)
\ No newline at end of file

--
Gitblit v1.9.1