|
|
@@ -5,12 +5,11 @@ from middleware import UnicornException
|
|
|
class SegmentService:
|
|
|
is_fall_file = ["扣图", "已扣图"]
|
|
|
is_fall_dir = ["微信"]
|
|
|
- need_cutout_images = []
|
|
|
- def initImages(self, image_list):
|
|
|
+ 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)
|
|
|
- self.need_cutout_images.append(
|
|
|
+ need_cutout_images.append(
|
|
|
{
|
|
|
"file_name": file_name,
|
|
|
"file_e": file_e,
|
|
|
@@ -21,19 +20,20 @@ class SegmentService:
|
|
|
}
|
|
|
)
|
|
|
|
|
|
- for index, image_data in enumerate(self.need_cutout_images):
|
|
|
+ for index, image_data in enumerate(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):
|
|
|
- self.need_cutout_images[index]["need_cutout"] = False
|
|
|
+ need_cutout_images[index]["need_cutout"] = False
|
|
|
continue
|
|
|
if os.path.exists(_path_2):
|
|
|
- self.need_cutout_images[index]["need_cutout"] = False
|
|
|
+ need_cutout_images[index]["need_cutout"] = False
|
|
|
continue
|
|
|
- return self.need_cutout_images
|
|
|
- def check_need_cutout_images(self, root_path):
|
|
|
+ return need_cutout_images
|
|
|
+
|
|
|
+ def check_need_cutout_images(self, root_path, need_cutout_images):
|
|
|
_n_c = 0
|
|
|
_Type = [
|
|
|
".jpg",
|
|
|
@@ -49,7 +49,7 @@ class SegmentService:
|
|
|
for file in os.listdir(root_path):
|
|
|
_n_c += 1
|
|
|
if _n_c > 500:
|
|
|
- self.need_cutout_images = []
|
|
|
+ need_cutout_images = []
|
|
|
raise UnicornException("目录下文件过多,请检查目录是否正确")
|
|
|
file_path = "{}/{}".format(root_path, file)
|
|
|
if os.path.isdir(file_path):
|
|
|
@@ -73,7 +73,7 @@ class SegmentService:
|
|
|
break
|
|
|
if f:
|
|
|
print("遍历文件夹", file_path)
|
|
|
- self.check_need_cutout_images(file_path)
|
|
|
+ self.check_need_cutout_images(file_path, need_cutout_images)
|
|
|
|
|
|
file_name, file_e = os.path.splitext(file)
|
|
|
if file_e not in _Type:
|
|
|
@@ -92,7 +92,7 @@ class SegmentService:
|
|
|
# need_cutout = False
|
|
|
|
|
|
# 图片进行处理
|
|
|
- self.need_cutout_images.append(
|
|
|
+ need_cutout_images.append(
|
|
|
{
|
|
|
"file_name": file_name,
|
|
|
"file_e": file_e,
|
|
|
@@ -102,4 +102,4 @@ class SegmentService:
|
|
|
"need_cutout": need_cutout,
|
|
|
}
|
|
|
)
|
|
|
- return self.need_cutout_images
|
|
|
+ return need_cutout_images
|