瀏覽代碼

精细化抠图

rambo 3 月之前
父節點
當前提交
09302325e2
共有 6 個文件被更改,包括 228 次插入139 次删除
  1. 7 7
      python/api.py
  2. 10 10
      python/service/base_deal.py
  3. 56 22
      python/service/deal_cutout.py
  4. 139 67
      python/service/deal_one_image.py
  5. 15 32
      python/service/run_main.py
  6. 1 1
      python/settings.py

+ 7 - 7
python/api.py

@@ -88,7 +88,7 @@ async def forwardRequest(request: HlmForwardRequest):
         raise UnicornException(e)
 
 
-def fromExcelHandler(params: HandlerDetail):
+async def fromExcelHandler(params: HandlerDetail):
     excel_path = params.excel_path
     token = "Bearer " + params.token
     uuid = params.uuid
@@ -166,9 +166,9 @@ def fromExcelHandler(params: HandlerDetail):
             shutil.rmtree(image_dir)
             # path = os.path.dirname(path)
     cutOutMode = (
-        0
+        '0'
         if settings.getSysConfigs("other_configs", "cutout_mode", "普通抠图") == "普通抠图"
-        else 1
+        else '1'
     )
     config_data = {
         "image_dir": limit_path,  # 这个目录作为本次生成的图片目录非常重要 例:./output/当前日期
@@ -309,7 +309,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
         # 如果是仅抠图模式,避免进入到excel模式
         params.excel_path = ""
     if params.excel_path != "" and params.excel_path != None:
-        return fromExcelHandler(params)
+        return await fromExcelHandler(params)
     # goods_art_list = run_main.data_mode_generate_detail.get_goods_art_no_info(
     #     goods_art_list=goods_art_no_arrays
     # )
@@ -365,10 +365,10 @@ async def handle_detail(request: Request, params: HandlerDetail):
         temp_class[tempItem.template_id] = tempItem.template_local_classes
         temp_name_list.append(tempItem.template_id)
     cutOutMode = (
-        0
+        '1'
         if settings.getSysConfigs("other_configs", "cutout_mode", "普通抠图")
         == "普通抠图"
-        else 1
+        else '2'
     )
     config_data = {
         "image_dir": limit_path,
@@ -410,7 +410,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
 
     config_data["temp_class"] = temp_class_dict
     return_data = run_main.check_before_cutout(config_data)
-    cutout_res = run_main.check_for_cutout_image_first_call_back(return_data)
+    cutout_res = await run_main.check_for_cutout_image_first_call_back(return_data)
     check_for_detail_first_res = None
     if cutout_res == True:
         sys_path = format(os.getcwd()).replace("\\", "/")

+ 10 - 10
python/service/base_deal.py

@@ -21,7 +21,7 @@ import datetime
 from databases import DeviceConfig,SqlQuery,CRUD
 from model.photo_record import PhotoRecord
 import requests
-import copy
+import copy, asyncio
 
 
 """
@@ -40,10 +40,10 @@ class BaseDealImage(object):
         self.image_dir = image_dir
         pass
 
-    def run_main(self, all_goods_art_no_folder_data, callback_func=None, cutout_mode=None,
+    async def run_main(self, all_goods_art_no_folder_data, callback_func=None, cutout_mode=None,
                  resize_image_view=None, windows=None, logo_path=None, image_order_list=None):
         # 对所有缺失已抠图的进行抠图处理
-        self.run_cutout_image(all_goods_art_no_folder_data=all_goods_art_no_folder_data,
+        await self.run_cutout_image(all_goods_art_no_folder_data=all_goods_art_no_folder_data,
                               callback_func=callback_func,
                               cutout_mode=cutout_mode,
                               windows=windows,
@@ -407,7 +407,7 @@ class BaseDealImage(object):
             path = "{}/{}".format(root_path, i)
             self.check_path(path)
 
-    def run_cutout_image(self, all_goods_art_no_folder_data, callback_func=None, cutout_mode=1, windows=None):
+    async def run_cutout_image(self, all_goods_art_no_folder_data, callback_func=None, cutout_mode=1, windows=None):
         """
         处理所有的抠图
         """
@@ -465,14 +465,14 @@ class BaseDealImage(object):
                                 callback_func("货号图{} 抠图完成~".format(file_name))
 
             if cutout_mode == '2':
-                dealCutout = DealCutout(windows=None)
+                dealCutout = DealCutout(windows=None, token=self.token)
                 dealCutout.need_cutout_images = cutImageList
-                dealCutout.run()
+                await dealCutout.run()
                 while True:
-                    time.sleep(1)
-                    if windows:
-                        if windows.state != 1:
-                            break
+                    await asyncio.sleep(1)
+                    # if windows:
+                    #     if windows.state != 1:
+                    #         break
                     if dealCutout.state == 3:
                         if len(dealCutout.resultData) != len(cutImageList):
                             error_goods_art_no_folder.append(folder_path)

+ 56 - 22
python/service/deal_cutout.py

@@ -3,6 +3,8 @@ import time
 from concurrent.futures import ThreadPoolExecutor, wait
 import threading
 
+from middleware import UnicornException
+
 from .deal_one_image import DealOneImage, DealOneImageBeforehand
 from logger import logger
 from .online_request.module_online_data import GetOnlineDataHLM
@@ -11,9 +13,10 @@ from .online_request.module_online_data import GetOnlineDataHLM
 class DealCutout():
     # signal_data = Signal(dict)
 
-    def __init__(self, windows):
+    def __init__(self, windows,token):
         super().__init__()
         self.windows = windows
+        self.token = token
         self.lock = threading.Lock()
         self.need_cutout_images = {}
         self.state = 2  # 1进行中 2停止  状态 用于中途取消, 3已结束
@@ -25,7 +28,7 @@ class DealCutout():
         self.logger = logger
 
         self.remaining_times = 0  # 剩余总次数
-        self.get_online_data = GetOnlineDataHLM()
+        self.get_online_data = GetOnlineDataHLM(token)
 
         self.resultData = [] # 最终的结果
 
@@ -53,14 +56,15 @@ class DealCutout():
     def check_before(self):
         self.refresh_times()
         if self.remaining_times <= 0:
-            self.send_sign({"type": "show_info",
-                            "message": "精细化抠图余量不足",
-                            })
+            # self.send_sign({"type": "show_info",
+            #                 "message": "精细化抠图余量不足",
+            #                 })
+            raise UnicornException("精细化抠图余量不足")
             return False
 
         return True
 
-    def run(self):
+    async def run(self):
         """
         need_cutout_images 结构:
         [
@@ -73,33 +77,63 @@ class DealCutout():
         ]
         """
         if not self.check_before():
-            self.signal_data.emit({"_type": "complete",
-                                   "data": []})
+            # self.signal_data.emit({"_type": "complete",
+            #                        "data": []})
             self.state = 3
             return
 
-        executor = ThreadPoolExecutor(max_workers=4)
-        executor_pic_upload = ThreadPoolExecutor(max_workers=2)
+        # executor = ThreadPoolExecutor(max_workers=4)
+        # executor_pic_upload = ThreadPoolExecutor(max_workers=2)
 
-        tasks_1 = []
-        tasks_2 = []
+        # tasks_1 = []
+        # tasks_2 = []
         self.state = 1
         self.resultData = []
         self.is_upload_pic_num = 0
         self.is_deal_num = 0
         num = 0
+        success_image_path = []
         for image_data in self.need_cutout_images:
             if not image_data["need_cutout"]:
                 continue
             num += 1
-            task_1 = executor.submit(DealOneImage(image_data=image_data, lock=self.lock, windows=self, num=num).run)
-            tasks_1.append(task_1)
-
-            task_2 = executor_pic_upload.submit(
-                DealOneImageBeforehand(image_data=image_data, lock=self.lock, windows=self, num=num).run)
-            tasks_2.append(task_2)
-        self.check_thread(tasks_1, tasks_2)
-
+            deal2 = DealOneImageBeforehand(
+                image_data=image_data,
+                lock=self.lock,
+                windows=self,
+                num=num,
+                token=self.token,
+            )
+            res2 = await deal2.run()
+            try:
+                image_path = res2
+                if image_path:
+                    if isinstance(image_path, str):
+                        if os.path.exists(image_path):
+                            success_image_path.append(image_path)
+            except BaseException as e:
+                self.logger.info("有线程出错:{}".format(e))
+            deal1 = DealOneImage(
+                image_data=image_data,
+                lock=self.lock,
+                windows=self,
+                num=num,
+                token=self.token,
+            )
+            res1 = await deal1.run()
+            # tasks_1.append(task_1)
+            print("res1===>", res1)
+            try:
+                image_path = res1
+                if image_path:
+                    if isinstance(image_path, str):
+                        if os.path.exists(image_path):
+                            success_image_path.append(image_path)
+            except BaseException as e:
+                self.logger.info("有线程出错:{}".format(e))
+        # self.check_thread(tasks_1, tasks_2)
+        self.resultData = success_image_path
+        self.state = 3
     def __del__(self):
         self.state = 2
 
@@ -127,7 +161,7 @@ class DealCutout():
             if f:
                 break
 
-        self.signal_data.emit({"_type": "complete",
-                               "data": success_image_path})
+        # self.signal_data.emit({"_type": "complete",
+        #                        "data": success_image_path})
         self.resultData = success_image_path
         self.state = 3

+ 139 - 67
python/service/deal_one_image.py

@@ -1,5 +1,7 @@
+import asyncio
 import copy
 import os.path
+
 # from module.other.module_online_data import GetOnlineData
 from .online_request.module_online_data import GetOnlineDataHLM
 
@@ -8,6 +10,7 @@ from logger import logger
 
 import os
 from PIL import Image
+
 # from module.other.remove_bg_ali import RemoveBgALi
 from .remove_bg_pixian import RemoveBgPiXian
 from .remove_bg_ali import RemoveBgALi, Picture
@@ -16,13 +19,14 @@ import numpy as np
 import settings
 import math
 
+
 class Base(object):
-    def __init__(self, image_data, lock, windows, num):
+    def __init__(self, image_data, lock, windows, num, token):
         self.lock = lock
         self.windows = windows
         self.image_data = image_data
         self.num = num
-        self.get_online_data = GetOnlineDataHLM()
+        self.get_online_data = GetOnlineDataHLM(token)
         self.file_path = image_data["file_path"]
         self.file_name = image_data["file_name"]
         self.file = os.path.split(self.file_path)[1]
@@ -30,9 +34,13 @@ class Base(object):
         self.logger = logger
 
     def add_log(self, text, _type="info"):
-        self.logger.info("第{}个,图片名称:{},内容:{}".format(self.num, self.file, text))
+        self.logger.info(
+            "第{}个,图片名称:{},内容:{}".format(self.num, self.file, text)
+        )
 
-    def send_info(self, text="", is_success=None, _type="show_info", need_point_return=False):
+    def send_info(
+        self, text="", is_success=None, _type="show_info", need_point_return=False
+    ):
         with self.lock:
             if is_success is not None:
                 if is_success:
@@ -42,15 +50,23 @@ class Base(object):
                     if need_point_return:
                         # 分数返回
                         if self.is_once("add_point"):
-                            print("第{}个,图片名称:{},内容:{}".format(self.num, self.file, "扣分返回"))
+                            print(
+                                "第{}个,图片名称:{},内容:{}".format(
+                                    self.num, self.file, "扣分返回"
+                                )
+                            )
                             self.dispose_point(_type="add")
-                            self.windows.remaining_times = self.windows.remaining_times + 1
+                            self.windows.remaining_times = (
+                                self.windows.remaining_times + 1
+                            )
 
             if text:
-                data = {"_type": _type,
-                        "data": text,
-                        }
-                self.windows.send_sign(data)
+                data = {
+                    "_type": _type,
+                    "data": text,
+                }
+                # self.windows.send_sign(data)
+                print("精细化抠图 send info ", data)
 
     def refresh_times(self, cumulative_frequency_times_change):
         if cumulative_frequency_times_change > 0:
@@ -83,8 +99,8 @@ class Base(object):
 
 
 class DealOneImage(Base):
-    def __init__(self, image_data, lock, windows, num):
-        super().__init__(image_data, lock, windows, num)
+    def __init__(self, image_data, lock, windows, num, token):
+        super().__init__(image_data, lock, windows, num, token)
         self.image_data = image_data
         self.lock = lock
         self.windows = windows
@@ -95,8 +111,9 @@ class DealOneImage(Base):
         self.file_name = image_data["file_name"]
         self.out_path = image_data["out_path"]
 
-    def run(self):
+    async def run(self):
         # 直接调用抠图
+        await asyncio.sleep(0.1)
         # 1、增加获取key,2、key需要加密、3、429报错 重试再来拿一个KEY
         self.add_log("开始处理")
         self.send_info(text="{} 处理中".format(self.file_name))
@@ -113,29 +130,30 @@ class DealOneImage(Base):
             n -= 1
             if self.file_path in self.windows.upload_pic_dict:
                 break
-
             else:
-                time.sleep(1)
+                await asyncio.sleep(1)
                 if n <= 0:
                     self.send_info(text="{} 处理超时", is_success=False)
                     return
                 continue
-
+        print("图片已上传============》》》》》》")
         s = time.time()
-        # print(self.upload_pic_dict[file_path])
+        # print(self.windows.upload_pic_dict,self.windows.upload_pic_dict[self.file_path], self.file_path)
         _flag = self.windows.upload_pic_dict[self.file_path]["flag"]
         if not _flag:
             self.add_log("未查到上传的图片地址")
             self.send_info(text="{} 上传错误", is_success=False)
             return
 
-        image_deal_info = self.windows.upload_pic_dict[self.file_path]["image_deal_info"]
+        image_deal_info = self.windows.upload_pic_dict[self.file_path][
+            "image_deal_info"
+        ]
         original_im = self.windows.upload_pic_dict[self.file_path]["_im"]
 
         self.add_log("抠图中")
 
-        with self.lock:
-            self.windows.is_upload_pic_num -= 1
+        # with self.lock:
+        self.windows.is_upload_pic_num -= 1
 
         try:
             balance = self.get_online_data.get_cutout_image_times()["balance"]
@@ -160,19 +178,23 @@ class DealOneImage(Base):
             self.add_log("查询key成功")
 
             if not key:
-                _data = {"text": "出错/超时",
-                         "info": "多次获取key失败",
-                         }
+                _data = {
+                    "text": "出错/超时",
+                    "info": "多次获取key失败",
+                }
                 self.add_log(text="多次获取key失败")
-                self.send_info(text="{} 处理失败,请联系管理员".format(self.file_name), is_success=False)
+                self.send_info(
+                    text="{} 处理失败,请联系管理员".format(self.file_name),
+                    is_success=False,
+                )
                 return
 
             if self.is_once("sub_point"):
                 # 调用扣分
-                with self.lock:
+                # with self.lock:
 
-                    self.refresh_times(cumulative_frequency_times_change=1)
-                    f = self.dispose_point(_type="sub")
+                self.refresh_times(cumulative_frequency_times_change=1)
+                f = self.dispose_point(_type="sub")
                 if not f:
                     self.add_log(text="多次获取调用余额扣减失败")
                     self.send_info(text="多次获取调用余额扣减失败", is_success=False)
@@ -188,33 +210,62 @@ class DealOneImage(Base):
 
             elif pixian_cutout_data["status_code"] == 402:
                 if n >= 2:
-                    self.add_log(text="多次抠图失败:{}".format(pixian_cutout_data["status_code"]))
-                    self.send_info(text="处理失败,请联系管理员", is_success=False, need_point_return=True)
+                    self.add_log(
+                        text="多次抠图失败:{}".format(pixian_cutout_data["status_code"])
+                    )
+                    self.send_info(
+                        text="处理失败,请联系管理员",
+                        is_success=False,
+                        need_point_return=True,
+                    )
                     if self.is_once("余额不足报错"):
                         # 余额不足报错,钉钉消息通知
-                        self.get_online_data.send_message("Pixian:{} 余额不足".format(key))
+                        self.get_online_data.send_message(
+                            "Pixian:{} 余额不足".format(key)
+                        )
                         pass
                     return
-                self.add_log(text="抠图失败:{},延迟6秒".format(pixian_cutout_data["status_code"]))
-                time.sleep(6)
+                self.add_log(
+                    text="抠图失败:{},延迟6秒".format(
+                        pixian_cutout_data["status_code"]
+                    )
+                )
+                await asyncio.sleep(6)
                 continue
 
             elif pixian_cutout_data["status_code"] == 429:
                 if n >= 2:
-                    self.add_log(text="多次抠图失败:{}".format(pixian_cutout_data["status_code"]))
-                    self.send_info(text="处理失败,请联系管理员", is_success=False, need_point_return=True)
+                    self.add_log(
+                        text="多次抠图失败:{}".format(pixian_cutout_data["status_code"])
+                    )
+                    self.send_info(
+                        text="处理失败,请联系管理员",
+                        is_success=False,
+                        need_point_return=True,
+                    )
                     return
 
-                self.add_log(text="{}抠图失败:{},延迟10秒".format(self.file_name, pixian_cutout_data["status_code"]))
-                time.sleep(10)
+                self.add_log(
+                    text="{}抠图失败:{},延迟10秒".format(
+                        self.file_name, pixian_cutout_data["status_code"]
+                    )
+                )
+                await asyncio.sleep(10)
                 continue
             else:
-                self.send_info(text="{} 处理失败,请联系管理员".format(self.file_name), is_success=False, need_point_return=True)
+                self.send_info(
+                    text="{} 处理失败,请联系管理员".format(self.file_name),
+                    is_success=False,
+                    need_point_return=True,
+                )
                 if "message" in pixian_cutout_data:
-                    text = "抠图异常,code:{},message:{}".format(pixian_cutout_data["status_code"],
-                                                            pixian_cutout_data["message"])
+                    text = "抠图异常,code:{},message:{}".format(
+                        pixian_cutout_data["status_code"], pixian_cutout_data["message"]
+                    )
                 else:
-                    text = "抠图异常,code:{}".format(pixian_cutout_data["status_code"])
+                    text = "抠图异常,code:{}".format(
+                        pixian_cutout_data["status_code"]
+                    )
                 self.add_log(text)
                 return
 
@@ -226,10 +277,20 @@ class DealOneImage(Base):
                 # print("图片尺寸还原")
                 self.add_log(text="图片尺寸进行还原")
                 original_im = image_deal_info["抠图扩边后PIL对象"]
-                second_cut_image = self.picture_resize_to_original(second_cut_image, original_im)
+                second_cut_image = self.picture_resize_to_original(
+                    second_cut_image, original_im
+                )
             # 创建空白图片并粘贴回去
-            _img_im = Image.new(mode="RGBA", size=image_deal_info["原始图片大小"], color=(0, 0, 0, 0))
-            _img_im.paste(second_cut_image, box=(image_deal_info["抠图扩边后位置"][0], image_deal_info["抠图扩边后位置"][1]))
+            _img_im = Image.new(
+                mode="RGBA", size=image_deal_info["原始图片大小"], color=(0, 0, 0, 0)
+            )
+            _img_im.paste(
+                second_cut_image,
+                box=(
+                    image_deal_info["抠图扩边后位置"][0],
+                    image_deal_info["抠图扩边后位置"][1],
+                ),
+            )
             _img_im.save(self.out_path)
 
             self.send_info(text="{} 抠图已完成".format(self.file_name), is_success=True)
@@ -257,13 +318,15 @@ class DealOneImage(Base):
 
         # 将抠图结果转成mask
         # 将抠图结果放大到原始图大小
-        _img = _img.resize(original_im.size,resample=1)
-        new_big_mask = Image.new('RGB', _img.size, (0, 0, 0))
-        white = Image.new('RGB', _img.size, (255, 255, 255))
+        _img = _img.resize(original_im.size, resample=1)
+        new_big_mask = Image.new("RGB", _img.size, (0, 0, 0))
+        white = Image.new("RGB", _img.size, (255, 255, 255))
         new_big_mask.paste(white, mask=_img.split()[3])
 
         # ---------制作选区缩小的mask
-        mask = cv2.cvtColor(np.asarray(new_big_mask), cv2.COLOR_BGR2GRAY)  # 将PIL 格式转换为 CV对象
+        mask = cv2.cvtColor(
+            np.asarray(new_big_mask), cv2.COLOR_BGR2GRAY
+        )  # 将PIL 格式转换为 CV对象
         mask[mask != 255] = 0
         # 黑白反转
         # mask = 255 - mask
@@ -272,9 +335,11 @@ class DealOneImage(Base):
         erode_im = cv2.morphologyEx(mask, cv2.MORPH_ERODE, kernel)
 
         # -------再进行抠图处理
-        mask = Image.fromarray(cv2.cvtColor(erode_im, cv2.COLOR_GRAY2RGBA))  # CV 对象转 PIL
-        transparent_im = Image.new('RGBA', original_im.size, (0, 0, 0, 0))
-        transparent_im.paste(original_im, (0, 0), mask.convert('L'))
+        mask = Image.fromarray(
+            cv2.cvtColor(erode_im, cv2.COLOR_GRAY2RGBA)
+        )  # CV 对象转 PIL
+        transparent_im = Image.new("RGBA", original_im.size, (0, 0, 0, 0))
+        transparent_im.paste(original_im, (0, 0), mask.convert("L"))
         # 上述抠图结果进行拼接
         _img.paste(transparent_im, (0, 0), transparent_im)
 
@@ -282,33 +347,32 @@ class DealOneImage(Base):
 
 
 class DealOneImageBeforehand(Base):
-    def __init__(self, image_data, lock, windows, num):
-        super().__init__(image_data, lock, windows, num)
+    def __init__(self, image_data, lock, windows, num,token):
+        super().__init__(image_data, lock, windows, num,token)
         self.image_data = image_data
         self.lock = lock
         self.windows = windows
-        self.get_online_data = GetOnlineDataHLM()
+        self.get_online_data = GetOnlineDataHLM(token)
         self.num = num
         self.file_path = image_data["file_path"]
         self.file = os.path.split(self.file_path)[1]
         self.r_ali = RemoveBgALi()
         self.file_name = image_data["file_name"]
 
-    def run(self):
+    async def run(self):
         while 1:
             if self.windows.state != 1:
                 return
 
-            with self.lock:
-                if self.windows.is_upload_pic_num >= 4:
+            if self.windows.is_upload_pic_num >= 4:
                     f = False
-                else:
+            else:
                     self.windows.is_upload_pic_num += 1
                     f = True
             if f:
                 break
             else:
-                time.sleep(1)
+                await asyncio.sleep(1)
                 continue
         image_deal_info = {}
         try:
@@ -317,15 +381,17 @@ class DealOneImageBeforehand(Base):
             f = True
             url = ""
         except BaseException as e:
+            print("精细化抠图错误",e)
             f = False
             url = ""
             cut_image = ""
 
-        with self.lock:
-            self.windows.upload_pic_dict[self.file_path] = {"url": url,
-                                                            "image_deal_info": image_deal_info,
-                                                            "flag": f,
-                                                            "_im": cut_image, }
+        self.windows.upload_pic_dict[self.file_path] = {
+            "url": url,
+            "image_deal_info": image_deal_info,
+            "flag": f,
+            "_im": cut_image,
+        }
 
     def get_image_cut(self):
         original_pic = Picture(self.file_path)
@@ -344,7 +410,9 @@ class DealOneImageBeforehand(Base):
             image_deal_info["抠图扩边后位置"] = (0, 0, original_pic.x, original_pic.y)
         else:
             self.add_log("开始预抠图处理")
-            cut_image = self.r_ali.get_image_cut(file_path=None, out_file_path=None, original_im=original_pic.im)
+            cut_image = self.r_ali.get_image_cut(
+                file_path=None, out_file_path=None, original_im=original_pic.im
+            )
 
             self.add_log("预抠图处理结束")
 
@@ -375,12 +443,16 @@ class DealOneImageBeforehand(Base):
             max_size = settings.MAX_PIXIAN_SIZE
             if x * y > max_size:
                 r = math.sqrt(max_size) / math.sqrt(x * y)
-                r = r*0.9
+                r = r * 0.9
                 size = (int(x * r), int(y * r))
                 # print("图片:{} pixian触发二次缩放,原尺寸{}*{},新尺寸:{}".format(self.file_name, x, y, size))
-                self.add_log(text="图片进行压缩,压缩前:{},压缩后:{}".format(image_deal_info["抠图扩边后图片大小"], size))
+                self.add_log(
+                    text="图片进行压缩,压缩前:{},压缩后:{}".format(
+                        image_deal_info["抠图扩边后图片大小"], size
+                    )
+                )
                 image_deal_info["抠图扩边后PIL对象"] = copy.deepcopy(cut_image)
-                cut_image = cut_image.resize(size=size,resample=1)
+                cut_image = cut_image.resize(size=size, resample=1)
                 # print(cut_image.size)
                 # print(image_deal_info["抠图扩边后PIL对象"].size)
                 image_deal_info["二次抠图是否缩放"] = True

+ 15 - 32
python/service/run_main.py

@@ -159,7 +159,7 @@ class RunMain():
         return return_data
 
     # 抠图校验后的回调函数处理
-    def check_for_cutout_image_first_call_back(self, return_data):
+    async def check_for_cutout_image_first_call_back(self, return_data):
         # return_data = {
         #     "code": 99,
         #     "message": "",
@@ -236,36 +236,22 @@ class RunMain():
             print("===============all_goods_art_no_folder_data===============")
             print(all_goods_art_no_folder_data)
 
-            new_func = partial(self.do_run_cutout_image,
-                               all_goods_art_no_folder_data=all_goods_art_no_folder_data,
-                               callback_func=self.show_progress_detail,
-                               image_order_list=return_data["data"]["image_order_list"],
-                               cutout_mode=return_data["data"]["cutout_mode"],
-                               resize_image_view=return_data["data"]["resize_image_view"],
-                               windows=None,
-                               logo_path=return_data["data"]["logo_path"],
-                               config_data=config_data)
-            return new_func()
-
-            # self.t = threading.Thread(target=self.do_run_cutout_image,
-            #                           kwargs={"all_goods_art_no_folder_data": all_goods_art_no_folder_data,
-            #                                   "callback_func": self.show_progress_detail,
-            #                                   "image_order_list": return_data["data"]["image_order_list"],
-            #                                   "cutout_mode": return_data["data"]["cutout_mode"],
-            #                                   "resize_image_view": return_data["data"]["resize_image_view"],
-            #                                   "windows": self.windows,
-            #                                   "logo_path": return_data["data"]["logo_path"],
-            #                                   "config_data": config_data,
-            #                                   })
-            # self.t.start()
-
+            new_func = await self.do_run_cutout_image(
+                all_goods_art_no_folder_data=all_goods_art_no_folder_data,
+                callback_func=self.show_progress_detail,
+                image_order_list=return_data["data"]["image_order_list"],
+                cutout_mode=return_data["data"]["cutout_mode"],
+                resize_image_view=return_data["data"]["resize_image_view"],
+                windows=None,
+                logo_path=return_data["data"]["logo_path"],
+                config_data=config_data,
+            )
+            return new_func
         else:
-            # config_data["sign_text"] = "已结束抠图处理"
-            # self.run_end_sign.emit(config_data)
             print("已结束抠图处理")
             return True
 
-    def do_run_cutout_image(self,
+    async def do_run_cutout_image(self,
                             all_goods_art_no_folder_data,
                             callback_func,
                             image_order_list,
@@ -275,7 +261,8 @@ class RunMain():
                             logo_path,
                             config_data):
         print("BaseDealImage().run_main========>>>>")
-        BaseDealImage(token=self.token).run_main(all_goods_art_no_folder_data=all_goods_art_no_folder_data,
+        deal = BaseDealImage(token=self.token)
+        await deal.run_main(all_goods_art_no_folder_data=all_goods_art_no_folder_data,
                                  callback_func=callback_func,
                                  image_order_list=image_order_list,
                                  cutout_mode=cutout_mode,
@@ -290,12 +277,8 @@ class RunMain():
             page="抠图结束",
             data=goods_arts,
         )
-        # ==============完成处理==============
-        # self.set_state(state_value=2)
         callback_func("已结束抠图处理")
         return True
-        # config_data["sign_text"] = "已结束抠图处理"
-        # self.run_end_sign.emit(config_data)
 
     def do_run_cutout_image1111(self, all_goods_art_no_folder_data,
                                 callback_func,

+ 1 - 1
python/settings.py

@@ -88,7 +88,7 @@ PhotographSeconds = float(
     if getSysConfigs("take_photo_configs", "camera_delay", "0.5") == ""
     else getSysConfigs("take_photo_configs", "camera_delay", "0.5")
 )  # 拍照停留时间
-
+MAX_PIXIAN_SIZE = 12000000
 
 def moveSpeed(level: str = None):
     config = {