Bladeren bron

生图抠图模式调整为最新

rambo 6 maanden geleden
bovenliggende
commit
ffd49d4eba

+ 1 - 1
python/api.py

@@ -305,7 +305,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
                     "\\", "/"
                 )
                 # print("out_put_dir_path", out_put_dir_path)
-                handler_result_folder = out_put_dir_path
+                handler_result_folder = os.path.dirname(out_put_dir_path)
                 handler_result.append(
                     {"goods_art_no": goods_art_no, "success": True, "info": "处理成功"}
                 )

+ 19 - 14
python/service/base_deal.py

@@ -96,6 +96,8 @@ class BaseDealImage(object):
                             callback_func("货号:{} 图片生成处理失败".format(folder_name))
                 except BaseException as e:
                     error_num += 1
+                    import traceback
+                    traceback.print_exc()
                     callback_func("货号:{} 图片生成处理异常,原因:{}".format(folder_name, e))
         callback_func("处理成功:{}个,失败:{}".format(successful_num, error_num))
 
@@ -208,7 +210,7 @@ class BaseDealImage(object):
         all_original_images = self.get_images("{}/原始图".format(folder_path))
         self.check_path('{}/800x800'.format(folder_path))
         self.crate_all_folders(folder_path)
-
+        print("all_original_images====>",all_original_images)
         if not all_original_images:
             return None
             # _ = ["俯视", "侧视", "后跟", "鞋底", "内里"]
@@ -330,18 +332,21 @@ class BaseDealImage(object):
                     max_box
                 )
             print("**********123456********************")
-            if not generate_pic.run(image_path=original_image_path,
-                                    cut_image_path=original_move_bg_image_path,
-                                    out_path=out_path,
-                                    image_deal_mode=is_image_deal_mode,
-                                    resize_mode=resize_mode,
-                                    out_pic_size=settings.OUT_PIC_SIZE,
-                                    is_logo=True if i_n == 1 else False,
-                                    out_process_path_1=out_process_path_1,
-                                    out_process_path_2=out_process_path_2,
-                                    max_box=max_box,
-                                    logo_path=logo_path,
-                                    ):
+            curve_mask = True if "俯视" in image_order_list else False
+            if not generate_pic.run(
+                image_path=original_image_path,
+                cut_image_path=original_move_bg_image_path,
+                out_path=out_path,
+                image_deal_mode=is_image_deal_mode,
+                resize_mode=resize_mode,
+                out_pic_size=settings.OUT_PIC_SIZE,
+                is_logo=True if i_n == 1 else False,
+                out_process_path_1=out_process_path_1,
+                out_process_path_2=out_process_path_2,
+                max_box=max_box,
+                logo_path=logo_path,
+                curve_mask=curve_mask,
+            ):
                 print("**********222222222222222222222222222********************")
                 is_successful = False
         if is_successful:
@@ -806,7 +811,7 @@ class BaseDealImage(object):
 
                 print("image_index", image_index)
                 image_index = 99
-                curve_mask = True if "俯视" in image_dict["image_view"] else False
+                curve_mask = True if "俯视" in image_order["image_view"] else False
                 if generate_pic.run(image_path=original_image_path,
                                     cut_image_path=original_move_bg_image_path,
                                     out_path=out_path,

+ 37 - 14
python/service/generate_main_image/image_deal_base_func.py

@@ -128,10 +128,16 @@ def find_lowest_non_transparent_points(cv2_png):
     return min_y_values
 
 
-def draw_shifted_line(image, min_y_values, shift_amount=15,
-                      one_line_pos=(0, 100),
-                      line_color=(0, 0, 0),
-                      line_thickness=20):
+def draw_shifted_line(
+    image,
+    min_y_values,
+    shift_amount=15,
+    one_line_pos=(0, 100),
+    line_color=(0, 0, 0),
+    line_thickness=20,
+    app=None,
+    crop_image_box=None,
+):
     """
     image:jpg cv2格式的原始图
     min_y_values 透明图中,不透明区域的最低那条线
@@ -145,11 +151,11 @@ def draw_shifted_line(image, min_y_values, shift_amount=15,
 
     # 对线条取转成图片
     shifted_min_y_values = np.clip(min_y_values + shift_amount, 0, image.shape[0] - 1)
-
     # 使用Numpy索引批量绘制直线
     min_y_threshold = 50  # Y轴像素小于50的不处理
     valid_x = (shifted_min_y_values >= min_y_threshold) & (shifted_min_y_values != -1)
 
+    # print("valid_x", len(valid_x))
     # 对曲线取平均值
     # # 对曲线取平均值
     # min_y = np.max(min_y_values)
@@ -158,23 +164,40 @@ def draw_shifted_line(image, min_y_values, shift_amount=15,
     # min_y_values_2 = min_y_values_2.astype(int)
     # shifted_min_y_values = np.clip(min_y_values_2 + shift_amount, 0, image.shape[0] - 1)
 
+    if settings.SHADOW_PROCESSING == 0:
+        if crop_image_box:
+            # 800像素宽;鞋子前后20%进行移除
+            shoe_width = crop_image_box[2] - crop_image_box[0]
+            _half_show_width = int(shoe_width * 0.15)
+            valid_x[: crop_image_box[0] + _half_show_width] = False
+            valid_x[crop_image_box[2] - _half_show_width :] = False
+
     x_coords = np.arange(image.shape[1])[valid_x]
     y_start = shifted_min_y_values[valid_x]
     y_end = y_start + line_thickness
 
-    # 使用Numpy广播机制创建线条区域的索引
-    for x, start, end in zip(x_coords, y_start, y_end):
-        image[start:end, x, :3] = line_color  # 只修改RGB通道
+    # todo 使用Numpy广播机制创建线条区域的索引
+    # todo 鞋子曲线线条
+    if settings.SHADOW_PROCESSING == 0:
+        for x, start, end in zip(x_coords, y_start, y_end):
+            image[start:end, x, :3] = line_color  # 只修改RGB通道
 
     # 计算整个图像的最低非透明点
-    lowest_y = np.max(min_y_values[min_y_values != -1]) if np.any(min_y_values != -1) else -1
+    lowest_y = (
+        np.max(min_y_values[min_y_values != -1]) if np.any(min_y_values != -1) else -1
+    )
     # 绘制原最低非透明点处的线
-    cv2.line(image, (one_line_pos[0], lowest_y + 5), (one_line_pos[1], lowest_y + 5), line_color,
-             thickness=line_thickness)
-
-    _y = lowest_y + 18
+    cv2.line(
+        image,
+        (one_line_pos[0], lowest_y + settings.LOWER_Y),
+        (one_line_pos[1], lowest_y + 5),
+        line_color,
+        thickness=line_thickness,
+    )
+    # 调整 _y = lowest_y + 18
+    _y = lowest_y + 200
     if _y > image.shape[0]:  # 超过图片尺寸
-        _y = image.shape[0] - 5
+        _y = image.shape[0] - settings.CHECK_LOWER_Y
     return image, _y
 
 

+ 44 - 34
python/service/grenerate_main_image_test.py

@@ -69,7 +69,7 @@ class GeneratePic(object):
             one_line_pos=(x1, x2),
             line_color=(0, 0, 0),
             line_thickness=20,
-            app=settings.app,
+            app=None,
             crop_image_box=crop_image_box,
         )
         print("66  制作蒙版")
@@ -140,8 +140,8 @@ class GeneratePic(object):
         xunhuan = 0
         while k:
             xunhuan += 1
-            if settings.app:
-                settings.app.processEvents()
+            # if settings.app:
+            #     settings.app.processEvents()
             k -= 1
             Midtones += 0.035
             if Midtones > 1.7:
@@ -222,7 +222,7 @@ class GeneratePic(object):
             one_line_pos=(x1, x2),
             line_color=(0, 0, 0),
             line_thickness=20,
-            app=settings.app,
+            app=None,
             crop_image_box=(x1, y1, x2, y2),
         )
         print("66  制作蒙版")
@@ -290,8 +290,8 @@ class GeneratePic(object):
         print("循环识别")
         while k:
             print("循环识别:{}".format(k))
-            if settings.app:
-                settings.app.processEvents()
+            # if settings.app:
+            #     settings.app.processEvents()
             k -= 1
             Midtones += 0.1
             if Midtones > 1:
@@ -556,38 +556,48 @@ class GeneratePic(object):
         if settings.OUT_PIC_FACTOR > 1.0:
             print("图片锐化处理")
             image_bg = sharpen_image(image_bg, factor=settings.OUT_PIC_FACTOR)
-
-        if out_pic_size < 1600:
-            image_bg = image_bg.resize(
-                (out_pic_size, out_pic_size), resample=settings.RESIZE_IMAGE_MODE
-            )
-
-        if settings.OUT_PIC_MODE == ".jpg":
-            if settings.OUT_PIC_QUALITY == "普通":
-                self.saver.save_image(
-                    image=image_bg,
-                    file_path=out_path,
-                    save_mode="jpg",
-                    quality=None,
-                    dpi=None,
-                    _format="JPEG",
+        for imageSize in out_pic_size:
+            dot_index = out_path.rfind(".")
+            if dot_index != -1:
+                    # 拆分文件路径和后缀
+                    file_without_suffix = out_path[:dot_index]
+                    suffix = out_path[dot_index + 1 :]
+            else:
+                    file_without_suffix = out_path
+                    suffix = ""
+                # 单独拼接字符串示例
+            new_file_path = f"{file_without_suffix}_{imageSize}.{suffix}"
+            if imageSize < 1600:
+                image_bg = image_bg.resize(
+                    (out_pic_size, out_pic_size), resample=settings.RESIZE_IMAGE_MODE
                 )
-                # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=None, dpi=None, _format="JPEG")
-                # image_bg.save(out_path, format="JPEG")
+                if settings.OUT_PIC_MODE == ".jpg":
+                    self.saver.save_image(
+                        image=image_bg,
+                        file_path=new_file_path,
+                        save_mode="jpg",
+                        quality=None,
+                        dpi=None,
+                        _format="JPEG",
+                    )
+                    # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=None, dpi=None, _format="JPEG")
+                    # image_bg.save(out_path, format="JPEG")
+                else:
+                    self.saver.save_image(
+                        image=image_bg,
+                        file_path=new_file_path,
+                        save_mode="jpg",
+                        quality=100,
+                        dpi=(300, 300),
+                        _format="JPEG",
+                    )
+                    # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=100, dpi=(300, 300), _format="JPEG")
+                    # image_bg.save(out_path, quality=100, dpi=(300, 300), format="JPEG")
             else:
                 self.saver.save_image(
-                    image=image_bg,
-                    file_path=out_path,
-                    save_mode="jpg",
-                    quality=100,
-                    dpi=(300, 300),
-                    _format="JPEG",
+                    image=image_bg, file_path=new_file_path, save_mode="png"
                 )
-                # save_image_by_thread(image_bg, out_path, save_mode="jpg", quality=100, dpi=(300, 300), _format="JPEG")
-                # image_bg.save(out_path, quality=100, dpi=(300, 300), format="JPEG")
-        else:
-            self.saver.save_image(image=image_bg, file_path=out_path, save_mode="png")
-            # image_bg.save(out_path)
+                # image_bg.save(out_path)
 
         if output_queue is not None:
             output_queue.put(True)

+ 39 - 29
python/service/image_deal_base_func.py

@@ -123,11 +123,16 @@ def find_lowest_non_transparent_points(cv2_png):
     return min_y_values
 
 
-def draw_shifted_line(image, min_y_values, shift_amount=15,
-                      one_line_pos=(0, 100),
-                      line_color=(0, 0, 0),
-                      line_thickness=20,
-                      app=None):
+def draw_shifted_line(
+    image,
+    min_y_values,
+    shift_amount=15,
+    one_line_pos=(0, 100),
+    line_color=(0, 0, 0),
+    line_thickness=20,
+    app=None,
+    crop_image_box=None,
+):
     """
     image:jpg cv2格式的原始图
     min_y_values 透明图中,不透明区域的最低那条线
@@ -137,22 +142,15 @@ def draw_shifted_line(image, min_y_values, shift_amount=15,
     """
     # 将最低Y值向下迁移20个像素,但确保不超过图片的高度
     # 创建空白图片
-    if app:
-        # TODO 待移除
-        app.processEvents()
     image = np.ones((image.shape[0], image.shape[1], 3), dtype=np.uint8) * 255
 
     # 对线条取转成图片
     shifted_min_y_values = np.clip(min_y_values + shift_amount, 0, image.shape[0] - 1)
-    if app:
-        # TODO 待移除
-        app.processEvents()
     # 使用Numpy索引批量绘制直线
     min_y_threshold = 50  # Y轴像素小于50的不处理
     valid_x = (shifted_min_y_values >= min_y_threshold) & (shifted_min_y_values != -1)
-    if app:
-        # TODO 待移除
-        app.processEvents()
+
+    # print("valid_x", len(valid_x))
     # 对曲线取平均值
     # # 对曲线取平均值
     # min_y = np.max(min_y_values)
@@ -161,28 +159,40 @@ def draw_shifted_line(image, min_y_values, shift_amount=15,
     # min_y_values_2 = min_y_values_2.astype(int)
     # shifted_min_y_values = np.clip(min_y_values_2 + shift_amount, 0, image.shape[0] - 1)
 
+    if settings.SHADOW_PROCESSING == 0:
+        if crop_image_box:
+            # 800像素宽;鞋子前后20%进行移除
+            shoe_width = crop_image_box[2] - crop_image_box[0]
+            _half_show_width = int(shoe_width * 0.15)
+            valid_x[: crop_image_box[0] + _half_show_width] = False
+            valid_x[crop_image_box[2] - _half_show_width :] = False
+
     x_coords = np.arange(image.shape[1])[valid_x]
     y_start = shifted_min_y_values[valid_x]
     y_end = y_start + line_thickness
 
-    # 使用Numpy广播机制创建线条区域的索引
-    for x, start, end in zip(x_coords, y_start, y_end):
-        image[start:end, x, :3] = line_color  # 只修改RGB通道
-    if app:
-        # TODO 待移除
-        app.processEvents()
+    # todo 使用Numpy广播机制创建线条区域的索引
+    # todo 鞋子曲线线条
+    if settings.SHADOW_PROCESSING == 0:
+        for x, start, end in zip(x_coords, y_start, y_end):
+            image[start:end, x, :3] = line_color  # 只修改RGB通道
+
     # 计算整个图像的最低非透明点
-    lowest_y = np.max(min_y_values[min_y_values != -1]) if np.any(min_y_values != -1) else -1
+    lowest_y = (
+        np.max(min_y_values[min_y_values != -1]) if np.any(min_y_values != -1) else -1
+    )
     # 绘制原最低非透明点处的线
-    cv2.line(image, (one_line_pos[0], lowest_y + 5), (one_line_pos[1], lowest_y + 5), line_color,
-             thickness=line_thickness)
-    if app:
-        # TODO 待移除
-        app.processEvents()
-
-    _y = lowest_y + 18
+    cv2.line(
+        image,
+        (one_line_pos[0], lowest_y + settings.LOWER_Y),
+        (one_line_pos[1], lowest_y + 5),
+        line_color,
+        thickness=line_thickness,
+    )
+    # 调整 _y = lowest_y + 18
+    _y = lowest_y + 200
     if _y > image.shape[0]:  # 超过图片尺寸
-        _y = image.shape[0] - 5
+        _y = image.shape[0] - settings.CHECK_LOWER_Y
     return image, _y
 
 

+ 5 - 1
python/sys_configs.json

@@ -9,7 +9,11 @@
     },
     {
         "key": "other_configs",
-        "value": "{\"product_type\":\"鞋类\",\"cutout_mode\":\"普通抠图\",\"device_speed\":\"二档\",\"running_mode\":\"普通模式\",\"grenerate_main_pic_brightness\":254,\"shadow_processing\":0,\"lower_y\":4,\"check_lower_y\":4,\"is_get_green_mask\":\"否\",\"image_save_max_workers\":4,\"color_gradation_cycles\":22}"
+        "value": "{\"product_type\":\"鞋类\",\"cutout_mode\":\"普通抠图\",\"device_speed\":\"二档\",\"running_mode\":\"普通模式\"}"
+    },
+    {
+        "key": "hidden_configs",
+        "value": "{\"grenerate_main_pic_brightness\":254,\"shadow_processing\":0,\"lower_y\":4,\"check_lower_y\":4,\"is_get_green_mask\":\"否\",\"image_save_max_workers\":4,\"color_gradation_cycles\":22}"
     },
     {
         "key": "action_configs",