瀏覽代碼

Merge branch 'dev-python'

rambo 11 月之前
父節點
當前提交
202c9301eb
共有 2 個文件被更改,包括 13 次插入16 次删除
  1. 1 1
      python/api.py
  2. 12 15
      python/services/SegmentService.py

+ 1 - 1
python/api.py

@@ -24,7 +24,7 @@ async def checkSelect(params: CheckSelectImages):
         need_cutout_images = service.initImages(image_list=image_list)
     else:
         need_cutout_images = service.check_need_cutout_images(file_path)
-    print("need_cutout_images",need_cutout_images)
+    # print("need_cutout_images",need_cutout_images)
     if len([x for x in need_cutout_images if x["need_cutout"]]) == 0:
         raise UnicornException("您所选文件夹下没有jpg/png图片,或对应图片已扣图")
     return success(need_cutout_images)

+ 12 - 15
python/services/SegmentService.py

@@ -5,13 +5,12 @@ from middleware import UnicornException
 class SegmentService:
     is_fall_file = ["扣图", "已扣图"]
     is_fall_dir = ["微信"]
-
+    need_cutout_images = []
     def initImages(self, image_list):
-        need_cutout_images = []
         for image_path in image_list:
             root_path, file = os.path.split(image_path)
             file_name, file_e = os.path.splitext(file)
-            need_cutout_images.append(
+            self.need_cutout_images.append(
                 {
                     "file_name": file_name,
                     "file_e": file_e,
@@ -22,21 +21,20 @@ class SegmentService:
                 }
             )
 
-        for index, image_data in enumerate(need_cutout_images):
+        for index, image_data in enumerate(self.need_cutout_images):
             root_path = image_data["root_path"]
             file_name = image_data["file_name"]
             _path_1 = "{}/{}.png".format(root_path, file_name)
             _path_2 = "{}/已扣图/{}.png".format(root_path, file_name)
             if os.path.exists(_path_1):
-                need_cutout_images[index]["need_cutout"] = False
+                self.need_cutout_images[index]["need_cutout"] = False
                 continue
             if os.path.exists(_path_2):
-                need_cutout_images[index]["need_cutout"] = False
+                self.need_cutout_images[index]["need_cutout"] = False
                 continue
-        return need_cutout_images
+        return self.need_cutout_images
     def check_need_cutout_images(self, root_path):
         _n_c = 0
-        need_cutout_images = []
         _Type = [
             ".jpg",
             ".JPG",
@@ -51,24 +49,22 @@ class SegmentService:
         for file in os.listdir(root_path):
             _n_c += 1
             if _n_c > 500:
-                need_cutout_images = []
+                self.need_cutout_images = []
                 raise UnicornException("目录下文件过多,请检查目录是否正确")
             file_path = "{}/{}".format(root_path, file)
             if os.path.isdir(file_path):
-                print("file_path", file_path, file)
+                # print("file_path", file_path, file)
                 if file == "已扣图":
                     # 哪些图片已经有抠图
                     for x_file in os.listdir(file_path):
                         x_file_name, x_file_e = os.path.splitext(x_file)
                         if x_file_e == ".png":
-                            # continue
                             _is_cutout.append(x_file_name)
-
         # ===============================================================
         for file in os.listdir(root_path):
             file_path = "{}/{}".format(root_path, file)
             if os.path.isdir(file_path):
-                print(file_path)
+                print("===>",file_path)
                 # 不是已扣图文件夹,则进行遍历
                 f = True
                 for i in self.is_fall_dir:
@@ -76,6 +72,7 @@ class SegmentService:
                         f = False
                         break
                 if f:
+                    print("遍历文件夹", file_path)
                     self.check_need_cutout_images(file_path)
 
             file_name, file_e = os.path.splitext(file)
@@ -95,7 +92,7 @@ class SegmentService:
             #     need_cutout = False
 
             # 图片进行处理
-            need_cutout_images.append(
+            self.need_cutout_images.append(
                 {
                     "file_name": file_name,
                     "file_e": file_e,
@@ -105,4 +102,4 @@ class SegmentService:
                     "need_cutout": need_cutout,
                 }
             )
-        return need_cutout_images
+        return self.need_cutout_images