修复design印花部分 mask_inv_print 提取错误
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
This commit is contained in:
@@ -27,7 +27,7 @@ class NoSegPrintPainting:
|
|||||||
# 获取平铺 + 旋转 的overall print
|
# 获取平铺 + 旋转 的overall print
|
||||||
painting_dict = self.painting_collection(painting_dict, overall_print)
|
painting_dict = self.painting_collection(painting_dict, overall_print)
|
||||||
result['no_seg_sketch_overall'] = result['no_seg_sketch_print'] = self.printpaint(result, painting_dict, print_=True)
|
result['no_seg_sketch_overall'] = result['no_seg_sketch_print'] = self.printpaint(result, painting_dict, print_=True)
|
||||||
result['pattern_image'] = result['no_seg_sketch_overall']
|
# result['pattern_image'] = result['no_seg_sketch_overall']
|
||||||
|
|
||||||
if single_print:
|
if single_print:
|
||||||
print_background = np.zeros((result['pattern_image'].shape[0], result['pattern_image'].shape[1], 3), dtype=np.uint8)
|
print_background = np.zeros((result['pattern_image'].shape[0], result['pattern_image'].shape[1], 3), dtype=np.uint8)
|
||||||
@@ -166,15 +166,17 @@ class NoSegPrintPainting:
|
|||||||
dim_max = max(painting_dict['dim_image_h'], painting_dict['dim_image_w'])
|
dim_max = max(painting_dict['dim_image_h'], painting_dict['dim_image_w'])
|
||||||
dim_pattern = (int(dim_max * print_['scale'] / 5), int(dim_max * print_['scale'] / 5))
|
dim_pattern = (int(dim_max * print_['scale'] / 5), int(dim_max * print_['scale'] / 5))
|
||||||
gap = print_dict.get('gap', [[0, 0]])[0]
|
gap = print_dict.get('gap', [[0, 0]])[0]
|
||||||
painting_dict['tile_print'] = tile_image(pattern=print_['image'],
|
painting_dict['tile_print'], painting_dict['mask_inv_print'] = tile_image(pattern=print_['image'],
|
||||||
dim=dim_pattern,
|
mask=print_['mask'],
|
||||||
gap_x=gap[0],
|
dim=dim_pattern,
|
||||||
gap_y=gap[1],
|
gap_x=gap[0],
|
||||||
canvas_h=painting_dict['dim_image_h'],
|
gap_y=gap[1],
|
||||||
canvas_w=painting_dict['dim_image_w'],
|
canvas_h=painting_dict['dim_image_h'],
|
||||||
location=painting_dict['location'],
|
canvas_w=painting_dict['dim_image_w'],
|
||||||
angle=int(print_.get('print_angle_list', [0])[0]))
|
location=painting_dict['location'],
|
||||||
painting_dict['mask_inv_print'] = np.zeros(painting_dict['tile_print'].shape[:2], dtype=np.uint8)
|
angle=int(print_.get('print_angle_list', [0])[0]))
|
||||||
|
# painting_dict['mask_inv_print'] = np.zeros(painting_dict['tile_print'].shape[:2], dtype=np.uint8)
|
||||||
|
# painting_dict['mask_inv_print'] = self.get_mask_inv(painting_dict['tile_print'])
|
||||||
return painting_dict
|
return painting_dict
|
||||||
|
|
||||||
def tile_image(self, pattern, dim, scale, dim_image_h, dim_image_w, location, trigger=False):
|
def tile_image(self, pattern, dim, scale, dim_image_h, dim_image_w, location, trigger=False):
|
||||||
@@ -255,10 +257,15 @@ class NoSegPrintPainting:
|
|||||||
image = oss_get_image(oss_client=self.minio_client, bucket=bucket_name, object_name=object_name, data_type="PIL")
|
image = oss_get_image(oss_client=self.minio_client, bucket=bucket_name, object_name=object_name, data_type="PIL")
|
||||||
# 判断图片格式,如果是RGBA 则贴在一张纯白图片上 防止透明转黑
|
# 判断图片格式,如果是RGBA 则贴在一张纯白图片上 防止透明转黑
|
||||||
if image.mode == "RGBA":
|
if image.mode == "RGBA":
|
||||||
|
mask_pil = image.split()[3]
|
||||||
new_background = Image.new('RGB', image.size, (255, 255, 255))
|
new_background = Image.new('RGB', image.size, (255, 255, 255))
|
||||||
new_background.paste(image, mask=image.split()[3])
|
new_background.paste(image, mask=image.split()[3])
|
||||||
image = new_background
|
image = new_background
|
||||||
|
else:
|
||||||
|
mask_pil = Image.new('L', image.size, 255) # L=灰度图,255=纯白
|
||||||
print_dict['image'] = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
|
print_dict['image'] = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
|
||||||
|
print_dict['mask'] = cv2.threshold(np.array(mask_pil), 127, 255, cv2.THRESH_BINARY)[1]
|
||||||
|
|
||||||
return print_dict
|
return print_dict
|
||||||
|
|
||||||
def crop_image(self, image, image_size_h, image_size_w, location, print_shape):
|
def crop_image(self, image, image_size_h, image_size_w, location, print_shape):
|
||||||
@@ -408,7 +415,7 @@ class NoSegPrintPainting:
|
|||||||
return cropped_img
|
return cropped_img
|
||||||
|
|
||||||
|
|
||||||
def tile_image(pattern, dim, gap_x, gap_y, canvas_h, canvas_w, location, angle=0):
|
def tile_image(pattern, mask, dim, gap_x, gap_y, canvas_h, canvas_w, location, angle=0):
|
||||||
"""
|
"""
|
||||||
按照指定的 X/Y 间距平铺印花,并支持旋转
|
按照指定的 X/Y 间距平铺印花,并支持旋转
|
||||||
:param angle: 旋转角度 (度数, 逆时针)
|
:param angle: 旋转角度 (度数, 逆时针)
|
||||||
@@ -448,9 +455,20 @@ def tile_image(pattern, dim, gap_x, gap_y, canvas_h, canvas_w, location, angle=0
|
|||||||
alpha_mask = cv2.merge([alpha_mask, alpha_mask, alpha_mask]) # 扩展到 3 通道
|
alpha_mask = cv2.merge([alpha_mask, alpha_mask, alpha_mask]) # 扩展到 3 通道
|
||||||
|
|
||||||
# 执行 Alpha 混合:结果 = 平铺层 * alpha + 背景 * (1 - alpha)
|
# 执行 Alpha 混合:结果 = 平铺层 * alpha + 背景 * (1 - alpha)
|
||||||
result = (tiled_bgr * alpha_mask + white_background * (1 - alpha_mask)).astype(np.uint8)
|
tiled_print = (tiled_bgr * alpha_mask + white_background * (1 - alpha_mask)).astype(np.uint8)
|
||||||
|
|
||||||
return result
|
resized_mask = cv2.resize(mask, dim, interpolation=cv2.INTER_NEAREST) # mask用最近邻,不模糊
|
||||||
|
rotated_mask = rotate_image(resized_mask, angle)
|
||||||
|
|
||||||
|
# 创建mask单元
|
||||||
|
unit_mask = np.zeros((cell_h, cell_w), dtype=np.uint8)
|
||||||
|
unit_mask[:p_h, :p_w] = rotated_mask
|
||||||
|
|
||||||
|
# 平铺mask
|
||||||
|
full_mask_tiled = np.tile(unit_mask, (tiles_y, tiles_x))
|
||||||
|
tiled_mask = full_mask_tiled[offset_y: offset_y + canvas_h, offset_x: offset_x + canvas_w]
|
||||||
|
|
||||||
|
return tiled_print, cv2.bitwise_not(tiled_mask)
|
||||||
|
|
||||||
|
|
||||||
def rotate_image(image, angle):
|
def rotate_image(image, angle):
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class PrintPainting:
|
|||||||
if overall_print['print_path_list']:
|
if overall_print['print_path_list']:
|
||||||
overall_print['location'][0] = [x * y for x, y in zip(overall_print['location'][0], result['resize_scale'])]
|
overall_print['location'][0] = [x * y for x, y in zip(overall_print['location'][0], result['resize_scale'])]
|
||||||
painting_dict = {'dim_image_h': result['pattern_image'].shape[0], 'dim_image_w': result['pattern_image'].shape[1]}
|
painting_dict = {'dim_image_h': result['pattern_image'].shape[0], 'dim_image_w': result['pattern_image'].shape[1]}
|
||||||
result['print_image'] = result['pattern_image']
|
result['print_image'] = result['pattern_image'].copy()
|
||||||
# 获取平铺 + 旋转 的overall print
|
# 获取平铺 + 旋转 的overall print
|
||||||
painting_dict = self.painting_collection(painting_dict, overall_print)
|
painting_dict = self.painting_collection(painting_dict, overall_print)
|
||||||
result['print_image'] = self.printpaint(result, painting_dict, print_=True)
|
result['print_image'] = self.printpaint(result, painting_dict, print_=True)
|
||||||
@@ -229,15 +229,15 @@ class PrintPainting:
|
|||||||
dim_max = max(painting_dict['dim_image_h'], painting_dict['dim_image_w'])
|
dim_max = max(painting_dict['dim_image_h'], painting_dict['dim_image_w'])
|
||||||
dim_pattern = (int(dim_max * print_['scale'] / 5), int(dim_max * print_['scale'] / 5))
|
dim_pattern = (int(dim_max * print_['scale'] / 5), int(dim_max * print_['scale'] / 5))
|
||||||
gap = print_dict.get('gap', [[0, 0]])[0]
|
gap = print_dict.get('gap', [[0, 0]])[0]
|
||||||
painting_dict['tile_print'] = tile_image(pattern=print_['image'],
|
painting_dict['tile_print'], painting_dict['mask_inv_print'] = tile_image(pattern=print_['image'],
|
||||||
dim=dim_pattern,
|
mask=print_['mask'],
|
||||||
gap_x=gap[0],
|
dim=dim_pattern,
|
||||||
gap_y=gap[1],
|
gap_x=gap[0],
|
||||||
canvas_h=painting_dict['dim_image_h'],
|
gap_y=gap[1],
|
||||||
canvas_w=painting_dict['dim_image_w'],
|
canvas_h=painting_dict['dim_image_h'],
|
||||||
location=painting_dict['location'],
|
canvas_w=painting_dict['dim_image_w'],
|
||||||
angle=int(print_.get('print_angle_list', [0])[0]))
|
location=painting_dict['location'],
|
||||||
painting_dict['mask_inv_print'] = np.zeros(painting_dict['tile_print'].shape[:2], dtype=np.uint8)
|
angle=int(print_.get('print_angle_list', [0])[0]))
|
||||||
return painting_dict
|
return painting_dict
|
||||||
|
|
||||||
def tile_image(self, pattern, dim, scale, dim_image_h, dim_image_w, location, trigger=False):
|
def tile_image(self, pattern, dim, scale, dim_image_h, dim_image_w, location, trigger=False):
|
||||||
@@ -318,10 +318,15 @@ class PrintPainting:
|
|||||||
image = oss_get_image(oss_client=self.minio_client, bucket=bucket_name, object_name=object_name, data_type="PIL")
|
image = oss_get_image(oss_client=self.minio_client, bucket=bucket_name, object_name=object_name, data_type="PIL")
|
||||||
# 判断图片格式,如果是RGBA 则贴在一张纯白图片上 防止透明转黑
|
# 判断图片格式,如果是RGBA 则贴在一张纯白图片上 防止透明转黑
|
||||||
if image.mode == "RGBA":
|
if image.mode == "RGBA":
|
||||||
|
mask_pil = image.split()[3]
|
||||||
new_background = Image.new('RGB', image.size, (255, 255, 255))
|
new_background = Image.new('RGB', image.size, (255, 255, 255))
|
||||||
new_background.paste(image, mask=image.split()[3])
|
new_background.paste(image, mask=image.split()[3])
|
||||||
image = new_background
|
image = new_background
|
||||||
|
else:
|
||||||
|
mask_pil = Image.new('L', image.size, 255) # L=灰度图,255=纯白
|
||||||
print_dict['image'] = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
|
print_dict['image'] = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
|
||||||
|
print_dict['mask'] = cv2.threshold(np.array(mask_pil), 127, 255, cv2.THRESH_BINARY)[1]
|
||||||
|
|
||||||
return print_dict
|
return print_dict
|
||||||
|
|
||||||
def crop_image(self, image, image_size_h, image_size_w, location, print_shape):
|
def crop_image(self, image, image_size_h, image_size_w, location, print_shape):
|
||||||
@@ -471,7 +476,7 @@ class PrintPainting:
|
|||||||
return cropped_img
|
return cropped_img
|
||||||
|
|
||||||
|
|
||||||
def tile_image(pattern, dim, gap_x, gap_y, canvas_h, canvas_w, location, angle=0):
|
def tile_image(pattern, mask, dim, gap_x, gap_y, canvas_h, canvas_w, location, angle=0):
|
||||||
"""
|
"""
|
||||||
按照指定的 X/Y 间距平铺印花,并支持旋转
|
按照指定的 X/Y 间距平铺印花,并支持旋转
|
||||||
:param angle: 旋转角度 (度数, 逆时针)
|
:param angle: 旋转角度 (度数, 逆时针)
|
||||||
@@ -511,9 +516,21 @@ def tile_image(pattern, dim, gap_x, gap_y, canvas_h, canvas_w, location, angle=0
|
|||||||
alpha_mask = cv2.merge([alpha_mask, alpha_mask, alpha_mask]) # 扩展到 3 通道
|
alpha_mask = cv2.merge([alpha_mask, alpha_mask, alpha_mask]) # 扩展到 3 通道
|
||||||
|
|
||||||
# 执行 Alpha 混合:结果 = 平铺层 * alpha + 背景 * (1 - alpha)
|
# 执行 Alpha 混合:结果 = 平铺层 * alpha + 背景 * (1 - alpha)
|
||||||
result = (tiled_bgr * alpha_mask + white_background * (1 - alpha_mask)).astype(np.uint8)
|
tiled_print = (tiled_bgr * alpha_mask + white_background * (1 - alpha_mask)).astype(np.uint8)
|
||||||
|
|
||||||
return result
|
# 处理mask的平铺
|
||||||
|
resized_mask = cv2.resize(mask, dim, interpolation=cv2.INTER_NEAREST) # mask用最近邻,不模糊
|
||||||
|
rotated_mask = rotate_image(resized_mask, angle)
|
||||||
|
|
||||||
|
# 创建mask单元
|
||||||
|
unit_mask = np.zeros((cell_h, cell_w), dtype=np.uint8)
|
||||||
|
unit_mask[:p_h, :p_w] = rotated_mask
|
||||||
|
|
||||||
|
# 平铺mask
|
||||||
|
full_mask_tiled = np.tile(unit_mask, (tiles_y, tiles_x))
|
||||||
|
tiled_mask = full_mask_tiled[offset_y: offset_y + canvas_h, offset_x: offset_x + canvas_w]
|
||||||
|
|
||||||
|
return tiled_print, cv2.bitwise_not(tiled_mask)
|
||||||
|
|
||||||
|
|
||||||
def rotate_image(image, angle):
|
def rotate_image(image, angle):
|
||||||
|
|||||||
Reference in New Issue
Block a user