rambo před 7 měsíci
rodič
revize
927401adf2

+ 20 - 0
python/api.py

@@ -21,6 +21,8 @@ from databases import DeviceConfig, SqlQuery, CRUD, select
 from service.run_main import RunMain
 import importlib
 from service.auto_deal_pics.upload_pic import UploadPic
+from service.OnePicTest import OnePicTest
+
 # from service.AutoDealPics import AutoDealPics
 # for plugin in settings.plugins:
 #     module_path, class_name = plugin.rsplit(".", 1)
@@ -563,3 +565,21 @@ def save_sys_configs(params: SysConfigParams):
         session, conditions={"key": params.key}, **kwargs
     )
     return {"code": 0, "msg": "操作成功", "data": save_device_config}
+
+
+@app.post("/create_main_image", description="创建主图测试")
+def save_sys_configs(params: MaineImageTest):
+    file_path = params.file_path
+    onePic = OnePicTest(pic_path=file_path)
+    # session = SqlQuery()
+    # sysConfig = CRUD(SysConfigs)
+    # model = sysConfig.read(session, conditions={"key": params.key})
+    # if model == None:
+    #     return {"code": 1, "msg": "配置不存在", "data": None}
+    # # 走编辑逻辑
+    # kwargs = params.__dict__
+    # save_device_config = sysConfig.updateConditions(
+    #     session, conditions={"key": params.key}, **kwargs
+    # )
+    main_out_path = onePic.HandlerMainImage()
+    return {"code": 0, "msg": "操作成功", "data": {"main_out_path": main_out_path}}

+ 4 - 4
python/mcu/ProgramItem.py

@@ -23,6 +23,7 @@ class ProgramItem(BaseClass):
         self.watch_dog = FileEventHandler()
         self.watch_dog.goods_art_no = goods_art_no
         self.watch_dog.image_index = image_index
+        self.watch_dog.mcu = mcu
         self.watch_dog.start_observer(captrure_folder_path)
         print("21 =========ProgramItem=======action_data=====")
         print(action_data)
@@ -274,10 +275,9 @@ class ProgramItem(BaseClass):
         # print("{} 拍照时间:{}".format(self.action_name, time.time() - start_time))
         print("{}-{}已完成".format(self.mode_type, self.action_name))
 
-        if True:
-            if self.after_delay_time:
-                print("拍照后延时:{}".format(self.after_delay_time))
-                time.sleep(self.after_delay_time)
+        if self.after_delay_time:
+            print("拍照后延时:{}".format(self.after_delay_time))
+            time.sleep(self.after_delay_time)
         return True
 
     def rephotograph_one_pic(self, *args):

+ 12 - 4
python/mcu/capture/module_watch_dog.py

@@ -7,7 +7,6 @@ from utils.utils_func import get_folder, check_path
 import datetime
 from utils.SingletonType import SingletonType
 from databases import CRUD,SqlQuery,PhotoRecord
-from databases import CRUD, SqlQuery, PhotoRecord
 def updateImageRaw(time_str, image_path, goods_art_no, image_index):
     session = SqlQuery()
     crud = CRUD(PhotoRecord)
@@ -43,6 +42,7 @@ class FileEventHandler(FileSystemEventHandler, metaclass=SingletonType):
         #     self.init_flag = True
         self.goods_art_no = None
         self.image_index = -1
+        self.mcu = None
         super().__init__()
         # self.window = window
         FileSystemEventHandler.__init__(self)
@@ -123,12 +123,20 @@ class FileEventHandler(FileSystemEventHandler, metaclass=SingletonType):
                 # print("获取文件create_time:{}".format(create_time))
                 self.get_photo_info(raw_path=file_path, create_time=create_time, take_time=take_time)
                 self.send_log("获取文件create_time:{}".format(create_time))
-                if self.goods_art_no == None:
-                    print("货号不存在,监听不写入")
-                    return
                 if file_path == None:
                     print("file_path不存在,监听不写入")
                     return
+                if self.goods_art_no == None:
+                    # print("货号不存在,监听不写入")
+                    self.mcu.msg_type = "run_mcu_single"
+                    self.mcu.sendSocketMessage(
+                        code=0,
+                        msg="主图测试拍摄完成",
+                        device_status=2,
+                        data={"file_path": file_path},
+                    )
+                    self.msg_type = "mcu"
+                    return
                 updateImageRaw(create_time, file_path, self.goods_art_no,self.image_index)
             except BaseException as e:
                 print("获取文件create_time失败", e)

+ 6 - 0
python/models.py

@@ -71,6 +71,12 @@ class TemplateItem(BaseModel):
     template_local_classes: str = Field(description="模板名称")
 
 
+class MaineImageTest(BaseModel):
+    """模板项"""
+
+    file_path: str = Field(description="图片地址")
+
+
 class HandlerDetail(BaseModel):
     """获取可执行程序命令列表"""
 

+ 93 - 0
python/service/OnePicTest.py

@@ -0,0 +1,93 @@
+import threading
+import time
+import os
+import settings
+
+from service.remove_bg_ali import RemoveBgALi
+from service.generate_main_image.grenerate_main_image_test import (
+    GeneratePic,
+)
+from service.generate_main_image.image_deal_base_func import *
+from functools import partial
+import io
+from PIL import Image
+from .base import check_path, get_date_time_original
+from middleware import UnicornException
+
+class OnePicTest():
+    # is_end = Signal()
+
+    def __init__(self,  pic_path="", is_auto_closed=False):
+        # super().__init__()
+        # 加载默认配置
+        # self.ui = Ui_Form()
+        # self.ui.setupUi(self)
+        self.pic_path = pic_path
+        self.is_auto_closed = False
+        # self.init()
+        # self.show()
+        # if pic_path:
+        #     self.run()
+
+    def call_back_deal_image(self, data):
+        # 处理后回调
+        print(data)
+        if data["code"] == 0:
+            return data
+        else:
+            if data["message"]:
+                raise UnicornException(data["message"])
+
+    def deal_image(self, image_path):
+        # 处理加工图片
+        return_data = {"code": 99, "message": "", "data": {}}
+
+        # =============清空temp文件夹================
+        check_path("temp")
+        check_path("temp\pic_test")
+        root = r"{}\temp\pic_test".format(os.getcwd())
+        for file_name in os.listdir(root):
+            path = "{}\{}".format(root, file_name)
+            if os.path.isfile(path):
+                os.remove(path)
+
+        # ==============抠图处理=====================
+        remove_pic_ins = RemoveBgALi()
+        file = os.path.split(image_path)[1]
+        cut_image_path = r"{}\temp\pic_test\{}.png".format(
+            os.getcwd(), os.path.splitext(file)[0]
+        )
+        remove_pic_ins.get_image_cut(file_path=image_path, out_file_path=cut_image_path)
+
+        # ==============生成主图====================
+        main_out_path = r"{}\temp\pic_test\{}-主图.jpg".format(
+            os.getcwd(), os.path.splitext(file)[0]
+        )
+        GeneratePic().run(
+            image_path=image_path,
+            cut_image_path=cut_image_path,
+            out_path=main_out_path,
+            image_deal_mode=1,
+            resize_mode=1,
+            out_pic_size=1024,
+            is_logo=False,
+        )
+
+        # return_data["code"] = 0
+        # return_data["data"]["image_path"] = image_path
+        # return_data["data"]["image_cutout_path"] = cut_image_path
+        # return_data["data"]["image_main_path"] = main_out_path
+        return main_out_path
+
+    def HandlerMainImage(self):
+        # 先做整体校验
+        if not os.path.exists(self.pic_path):
+            raise UnicornException("图片不存在")
+        return_data = self.deal_image(self.pic_path)
+        if return_data["message"]:
+            raise UnicornException(return_data["message"])
+        return return_data
+
+if __name__ == "__main__":
+    pic = OnePicTest(pic_path="C:/Users/15001/Desktop/mmexport1739929178317.jpg")
+    pic.HandlerMainImage()