feat(新功能): 1、design-print为解决sketch原图太灰导致印花颜色便暗 2、cv2.resize 插值算法更换,提升resize后图片质量 fix(修复bug): refactor(重构): test(增加测试):
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
@@ -38,12 +39,42 @@ class LoadImage:
|
||||
|
||||
def __call__(self, result):
|
||||
result['image'], result['pre_mask'] = self.read_image(result['path'])
|
||||
result['gray'] = cv2.cvtColor(result['image'], cv2.COLOR_BGR2GRAY)
|
||||
# if 'extract_lines' in result.keys():
|
||||
# if result['extract_lines']:
|
||||
# result['gray'] = self.get_lines(cv2.cvtColor(result['image'], cv2.COLOR_BGR2GRAY), result['path'])
|
||||
# else:
|
||||
# result['gray'] = cv2.cvtColor(result['image'], cv2.COLOR_BGR2GRAY)
|
||||
# else:
|
||||
# result['gray'] = cv2.cvtColor(result['image'], cv2.COLOR_BGR2GRAY)
|
||||
|
||||
result['gray'] = self.get_lines(cv2.cvtColor(result['image'], cv2.COLOR_BGR2GRAY), result['path'])
|
||||
result['keypoint'] = self.get_keypoint(result['name'])
|
||||
result['img_shape'] = result['image'].shape
|
||||
result['ori_shape'] = result['image'].shape
|
||||
return result
|
||||
|
||||
def get_lines(self, img, path):
|
||||
binary = cv2.adaptiveThreshold(img, 255,
|
||||
cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
|
||||
cv2.THRESH_BINARY_INV,
|
||||
25, 10)
|
||||
|
||||
# 步骤2:细化边缘(可选,让线条更干净)
|
||||
# kernel = np.ones((1, 1), np.uint8)
|
||||
# clean = cv2.morphologyEx(binary, cv2.MORPH_OPEN, kernel)
|
||||
|
||||
thinned = cv2.ximgproc.thinning(binary, thinningType=cv2.ximgproc.THINNING_ZHANGSUEN) # thinning算法细化线条
|
||||
mask = thinned > 0
|
||||
result = np.ones_like(img) * 255
|
||||
result[mask] = img[mask]
|
||||
|
||||
# 步骤3:反转回 白底黑线
|
||||
# lines = cv2.bitwise_not(thinned)
|
||||
# cv2.imwrite(os.path.join('/home/user/PycharmProjects/trinity_client_aida/test/lines_original_result_5', f"Original_{path.replace('/', '-')}.png"), img)
|
||||
# cv2.imwrite(os.path.join('/home/user/PycharmProjects/trinity_client_aida/test/lines_original_result_5', f"Line_{path.replace('/', '-')}.png"), result)
|
||||
|
||||
return result
|
||||
|
||||
def read_image(self, image_path):
|
||||
image_mask = None
|
||||
image = oss_get_image(oss_client=self.minio_client, bucket=image_path.split("/", 1)[0], object_name=image_path.split("/", 1)[1], data_type="cv2")
|
||||
|
||||
Reference in New Issue
Block a user