feat design 预处理新增padding 处理 使图片不要完全贴边

fix
This commit is contained in:
zhouchengrong
2024-08-01 10:08:25 +08:00
parent b9b31d2627
commit 58bc68ff5e

View File

@@ -60,6 +60,7 @@ class DesignPreprocessing:
def bounding_box(self, image_list):
for item in image_list:
image = item['image_obj']
height, width = image.shape[:2]
# 使用Canny边缘检测来检测物体的轮廓
edges = cv2.Canny(image, 50, 150)
# 查找轮廓
@@ -83,16 +84,25 @@ class DesignPreprocessing:
if len(contours) > 0:
cropped_image = image[y_min:y_max, x_min:x_max]
item['obj'] = cropped_image # 新shape图像
# 取消直接覆盖新增size判断
# try:
# # 覆盖到minio
# image_bytes = cv2.imencode(".jpg", cropped_image)[1].tobytes()
# self.minio_client.put_object(item['image_url'].split("/", 1)[0], item['image_url'].split("/", 1)[1], io.BytesIO(image_bytes), len(image_bytes), content_type="image/jpeg", )
# print(f"Object '{item['image_url'].split('/', 1)[1]}' overwritten successfully.")
# except ResponseError as err:
# print(f"Error: {err}")
else:
item['obj'] = image
padding_top = max(20 - y_min, 0)
padding_bottom = max(20 - (height - y_max), 0)
padding_left = max(20 - x_min, 0)
padding_right = max(20 - (width - x_max), 0)
# 添加padding
padded_image = cv2.copyMakeBorder(
image,
padding_top,
padding_bottom,
padding_left,
padding_right,
cv2.BORDER_CONSTANT,
value=(255, 255, 255) # 你可以选择填充颜色,例如黑色
)
item['obj'] = padded_image
return image_list
def super_resolution(self, image_list):
@@ -334,7 +344,7 @@ class DesignPreprocessing:
]
try:
# connections.connect(alias=MILVUS_ALIAS, host=MILVUS_DB_HOST, port=MILVUS_PORT)
start_time = time.time()
# start_time = time.time()
# collection = Collection(MILVUS_TABLE_KEYPOINT) # Get an existing collection.
# mr = collection.upsert(data)
# logging.info(f"save keypoint time : {time.time() - start_time}")
@@ -348,9 +358,9 @@ if __name__ == '__main__':
data = {
"sketches": [
{
"image_category": "dress",
"image_id": "107903",
"image_url": "aida-sys-image/images/female/dress/0628000000.jpg"
"image_category": "blouse",
"image_id": "123123123",
"image_url": "test/0628000198.jpg"
}
]
}