From 563f7741ad28a6a578b56c98c27f92b3677958bd Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期三, 23 三月 2022 15:35:11 +0800
Subject: [PATCH] Merge dev commit '28668532ed2f97a3883be7e68bced252bd1f99bf' into addFeature

---
 src/utils/tools.py |   33 ++++++++++++++++++++++++++++++---
 1 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/src/utils/tools.py b/src/utils/tools.py
index 3531cb3..80b55d1 100644
--- a/src/utils/tools.py
+++ b/src/utils/tools.py
@@ -1,7 +1,9 @@
 import os, sys
 import numpy as np
+import time
+from tqdm import tqdm
 
-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 = []
@@ -10,8 +12,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
 
@@ -38,6 +42,29 @@
     return ply_array
 
 
+def write_ply(data:np.array,folder:str,name:str):
+    file = os.path.join(folder,name+".ply")
+    with open (file,'w') as f:
+        f.write("ply\n")
+        f.write("format ascii 1.0\n")
+        f.write("comment write_ply generated\n")
+        f.write("element vertex %d\n" % data.shape[0])
+        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 tqdm(data):
+            x = p[0]
+            y = p[1]
+            z = p[2]
+            f.write("{:.5f} {:.5f} {:.5f}\n".format(x, y, z))
+            n_p += 1
+        print(time.asctime(),f"Frame {name}.ply have been saved with {n_p} points!")
+
 
 
 if __name__ == "__main__":

--
Gitblit v1.9.1