|
@@ -127,6 +127,8 @@ class DealOneImage(Base):
|
|
|
self.file = os.path.split(self.file_path)[1]
|
|
self.file = os.path.split(self.file_path)[1]
|
|
|
self.root_path = image_data["root_path"]
|
|
self.root_path = image_data["root_path"]
|
|
|
self.file_name = image_data["file_name"]
|
|
self.file_name = image_data["file_name"]
|
|
|
|
|
+ cut_status = False
|
|
|
|
|
+ success_path = ""
|
|
|
# 直接调用抠图
|
|
# 直接调用抠图
|
|
|
# 1、增加获取key,2、key需要加密、3、429报错 重试再来拿一个KEY
|
|
# 1、增加获取key,2、key需要加密、3、429报错 重试再来拿一个KEY
|
|
|
self.add_log("开始处理")
|
|
self.add_log("开始处理")
|
|
@@ -179,20 +181,24 @@ class DealOneImage(Base):
|
|
|
image_deal_info["抠图扩边后位置"][1],
|
|
image_deal_info["抠图扩边后位置"][1],
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
|
|
+ if self.windows.output_type == 1:
|
|
|
|
|
+ background = Image.new("RGBA", _img_im.size, (255, 255, 255, 255))
|
|
|
|
|
+ _img_im = Image.alpha_composite(background, _img_im)
|
|
|
|
|
+ cut_status = True
|
|
|
|
|
+ success_path = out_path
|
|
|
_img_im.save(out_path)
|
|
_img_im.save(out_path)
|
|
|
|
|
|
|
|
except BaseException as e:
|
|
except BaseException as e:
|
|
|
- # print(e)
|
|
|
|
|
text = "{} 图片处理错误,代码44".format(e)
|
|
text = "{} 图片处理错误,代码44".format(e)
|
|
|
self.add_log(text)
|
|
self.add_log(text)
|
|
|
self.send_info(text=text, is_success=False, need_point_return=True)
|
|
self.send_info(text=text, is_success=False, need_point_return=True)
|
|
|
- _data = {"text": "出错/超时", "info": text, "status": False}
|
|
|
|
|
- return _data
|
|
|
|
|
|
|
+ cut_status = False
|
|
|
|
|
|
|
|
self.add_log(text="本张耗时:{}".format(time.time() - s))
|
|
self.add_log(text="本张耗时:{}".format(time.time() - s))
|
|
|
self.send_info(text="抠图已完成", is_success=True)
|
|
self.send_info(text="抠图已完成", is_success=True)
|
|
|
- result = {"text": "已完成", "info": "", "status": True}
|
|
|
|
|
- return result
|
|
|
|
|
|
|
+ image_data["status"] = cut_status
|
|
|
|
|
+ image_data["success_path"] = success_path
|
|
|
|
|
+ return image_data
|
|
|
|
|
|
|
|
def runPiXian(self, num, original_im):
|
|
def runPiXian(self, num, original_im):
|
|
|
"""执行pixian抠图"""
|
|
"""执行pixian抠图"""
|
|
@@ -346,8 +352,6 @@ class DealOneImageBeforehand(Base):
|
|
|
cut_image = self.r_ali.get_image_cut(
|
|
cut_image = self.r_ali.get_image_cut(
|
|
|
file_path=None, out_file_path=None, original_im=original_pic.im
|
|
file_path=None, out_file_path=None, original_im=original_pic.im
|
|
|
)
|
|
)
|
|
|
- cut_image.save("XX1.png")
|
|
|
|
|
-
|
|
|
|
|
self.add_log("预抠图处理结束")
|
|
self.add_log("预抠图处理结束")
|
|
|
|
|
|
|
|
x1, y1, x2, y2 = cut_image.getbbox()
|
|
x1, y1, x2, y2 = cut_image.getbbox()
|
|
@@ -391,7 +395,51 @@ class DealOneImageBeforehand(Base):
|
|
|
image_deal_info["二次抠图是否缩放"] = False
|
|
image_deal_info["二次抠图是否缩放"] = False
|
|
|
return cut_image, image_deal_info
|
|
return cut_image, image_deal_info
|
|
|
|
|
|
|
|
- def get_image_cut_cloths(self):
|
|
|
|
|
|
|
+ def get_image_cut_noraml(self, image_data):
|
|
|
|
|
+ """普通模式抠图"""
|
|
|
|
|
+ self.file_path = image_data["file_path"]
|
|
|
|
|
+ self.file = os.path.split(self.file_path)[1]
|
|
|
|
|
+ self.root_path = image_data["root_path"]
|
|
|
|
|
+ self.file_name = image_data["file_name"]
|
|
|
|
|
+ original_pic = Picture(self.file_path)
|
|
|
|
|
+ original_pic.im = self.get_image_orientation(original_pic.im)
|
|
|
|
|
+ original_pic.x, original_pic.y = original_pic.im.size
|
|
|
|
|
+
|
|
|
|
|
+ original_pic.im = original_pic.im.convert("RGB")
|
|
|
|
|
+ image_deal_info = {}
|
|
|
|
|
+ image_deal_info["原始图片大小"] = (original_pic.x, original_pic.y)
|
|
|
|
|
+ self.add_log("开始预抠图处理")
|
|
|
|
|
+ remaining_times = self.get_online_data.get_cutout_image_times().get("balance")
|
|
|
|
|
+ print("remaining_times", remaining_times)
|
|
|
|
|
+ if remaining_times <= 0:
|
|
|
|
|
+ raise UnicornException("次数不足,处理失败")
|
|
|
|
|
+ self.get_online_data.dispose_point("sub")
|
|
|
|
|
+ cut_image = self.r_ali.get_image_cut(
|
|
|
|
|
+ file_path=None, out_file_path=None, original_im=original_pic.im
|
|
|
|
|
+ )
|
|
|
|
|
+ success_path = ""
|
|
|
|
|
+ if cut_image is None:
|
|
|
|
|
+ cut_status = False
|
|
|
|
|
+ self.get_online_data.dispose_point("add")
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.add_log("预抠图处理结束")
|
|
|
|
|
+ cut_status = True
|
|
|
|
|
+ save_root_path = "{}/已扣图".format(self.root_path)
|
|
|
|
|
+ self.check_path(save_root_path)
|
|
|
|
|
+ if self.windows.output_type == 1:
|
|
|
|
|
+ background = Image.new("RGBA", cut_image.size, (255, 255, 255, 255))
|
|
|
|
|
+ cut_image = Image.alpha_composite(background, cut_image)
|
|
|
|
|
+ success_path = "{}/{}.png".format(save_root_path, self.file_name)
|
|
|
|
|
+ cut_image.save(success_path)
|
|
|
|
|
+ image_data["status"] = cut_status
|
|
|
|
|
+ image_data["success_path"] = success_path
|
|
|
|
|
+ return image_data
|
|
|
|
|
+
|
|
|
|
|
+ def get_image_cut_cloths(self, image_data):
|
|
|
|
|
+ self.file_path = image_data["file_path"]
|
|
|
|
|
+ self.file = os.path.split(self.file_path)[1]
|
|
|
|
|
+ self.root_path = image_data["root_path"]
|
|
|
|
|
+ self.file_name = image_data["file_name"]
|
|
|
original_pic = Picture(self.file_path)
|
|
original_pic = Picture(self.file_path)
|
|
|
original_pic.im = self.get_image_orientation(original_pic.im)
|
|
original_pic.im = self.get_image_orientation(original_pic.im)
|
|
|
original_pic.x, original_pic.y = original_pic.im.size
|
|
original_pic.x, original_pic.y = original_pic.im.size
|
|
@@ -408,51 +456,28 @@ class DealOneImageBeforehand(Base):
|
|
|
cut_images = self.r_ali.get_image_cut_cloths(
|
|
cut_images = self.r_ali.get_image_cut_cloths(
|
|
|
file_path=None, out_file_path=None, original_im=original_pic.im
|
|
file_path=None, out_file_path=None, original_im=original_pic.im
|
|
|
)
|
|
)
|
|
|
- if cut_images is None:
|
|
|
|
|
|
|
+ success_path = ""
|
|
|
|
|
+ if cut_images is None or len(cut_images) == 0:
|
|
|
|
|
+ cut_status = False
|
|
|
self.get_online_data.dispose_point("add")
|
|
self.get_online_data.dispose_point("add")
|
|
|
- self.add_log("预抠图处理结束")
|
|
|
|
|
- print("cut_images", cut_images)
|
|
|
|
|
- return
|
|
|
|
|
- x1, y1, x2, y2 = cut_image.getbbox()
|
|
|
|
|
- image_deal_info["鞋子原始位置"] = (x1, y1, x2, y2)
|
|
|
|
|
- o_w, o_h = cut_image.size
|
|
|
|
|
- image_deal_info["鞋子原始抠图后大小"] = (o_w, o_h)
|
|
|
|
|
- # 扩边处理
|
|
|
|
|
- _w, _h = x2 - x1, y2 - y1
|
|
|
|
|
- out_px = 0.025
|
|
|
|
|
- _w, _h = int(out_px * _w), int(out_px * _h)
|
|
|
|
|
- n_x1, n_y1, n_x2, n_y2 = x1 - _w, y1 - _h, x2 + _w, y2 + _h
|
|
|
|
|
- if n_x1 < 0:
|
|
|
|
|
- n_x1 = 0
|
|
|
|
|
- if n_y1 < 0:
|
|
|
|
|
- n_y1 = 0
|
|
|
|
|
- if n_x2 > o_w:
|
|
|
|
|
- n_x2 = o_w
|
|
|
|
|
- if n_y2 > o_h:
|
|
|
|
|
- n_y2 = o_h
|
|
|
|
|
- image_deal_info["抠图扩边后位置"] = (n_x1, n_y1, n_x2, n_y2)
|
|
|
|
|
- cut_image = original_pic.im.crop(image_deal_info["抠图扩边后位置"])
|
|
|
|
|
-
|
|
|
|
|
- image_deal_info["抠图扩边后图片大小"] = cut_image.size
|
|
|
|
|
- x, y = image_deal_info["抠图扩边后图片大小"]
|
|
|
|
|
- # max_size = 32000000
|
|
|
|
|
- max_size = 12000000
|
|
|
|
|
- if x * y > max_size:
|
|
|
|
|
- r = max_size / (x * y)
|
|
|
|
|
- size = (int(x * r), int(y * r))
|
|
|
|
|
- self.add_log(
|
|
|
|
|
- text="图片进行压缩,压缩前:{},压缩后:{}".format(
|
|
|
|
|
- image_deal_info["抠图扩边后图片大小"], size
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- image_deal_info["抠图扩边后PIL对象"] = copy.deepcopy(cut_image)
|
|
|
|
|
- cut_image = cut_image.resize(size=size)
|
|
|
|
|
- # print(cut_image.size)
|
|
|
|
|
- # print(image_deal_info["抠图扩边后PIL对象"].size)
|
|
|
|
|
- image_deal_info["二次抠图是否缩放"] = True
|
|
|
|
|
else:
|
|
else:
|
|
|
- image_deal_info["二次抠图是否缩放"] = False
|
|
|
|
|
- return cut_image, image_deal_info
|
|
|
|
|
|
|
+ self.add_log("预抠图处理结束")
|
|
|
|
|
+ cut_status = True
|
|
|
|
|
+ save_root_path = "{}/已扣图".format(self.root_path)
|
|
|
|
|
+ self.check_path(save_root_path)
|
|
|
|
|
+ save_file_path = "{}/{}".format(save_root_path, self.file_name)
|
|
|
|
|
+ self.check_path(save_file_path)
|
|
|
|
|
+ success_path = save_file_path
|
|
|
|
|
+ for idx, item in enumerate(cut_images):
|
|
|
|
|
+ cn_name = item.get("cn_name")
|
|
|
|
|
+ image_obj = item.get("image_obj")
|
|
|
|
|
+ if self.windows.output_type == 1:
|
|
|
|
|
+ background = Image.new("RGBA", image_obj.size, (255, 255, 255, 255))
|
|
|
|
|
+ image_obj = Image.alpha_composite(background, image_obj)
|
|
|
|
|
+ image_obj.save("{}/{}.png".format(save_file_path, cn_name))
|
|
|
|
|
+ image_data["status"] = cut_status
|
|
|
|
|
+ image_data["success_path"] = success_path
|
|
|
|
|
+ return image_data
|
|
|
|
|
|
|
|
def get_image_orientation(self, img):
|
|
def get_image_orientation(self, img):
|
|
|
# 获取EXIF数据
|
|
# 获取EXIF数据
|