feat design 预处理新增padding 处理 使图片不要完全贴边
fix
This commit is contained in:
@@ -60,6 +60,7 @@ class DesignPreprocessing:
|
|||||||
def bounding_box(self, image_list):
|
def bounding_box(self, image_list):
|
||||||
for item in image_list:
|
for item in image_list:
|
||||||
image = item['image_obj']
|
image = item['image_obj']
|
||||||
|
height, width = image.shape[:2]
|
||||||
# 使用Canny边缘检测来检测物体的轮廓
|
# 使用Canny边缘检测来检测物体的轮廓
|
||||||
edges = cv2.Canny(image, 50, 150)
|
edges = cv2.Canny(image, 50, 150)
|
||||||
# 查找轮廓
|
# 查找轮廓
|
||||||
@@ -83,16 +84,25 @@ class DesignPreprocessing:
|
|||||||
if len(contours) > 0:
|
if len(contours) > 0:
|
||||||
cropped_image = image[y_min:y_max, x_min:x_max]
|
cropped_image = image[y_min:y_max, x_min:x_max]
|
||||||
item['obj'] = cropped_image # 新shape图像
|
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:
|
else:
|
||||||
item['obj'] = image
|
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
|
return image_list
|
||||||
|
|
||||||
def super_resolution(self, image_list):
|
def super_resolution(self, image_list):
|
||||||
@@ -334,7 +344,7 @@ class DesignPreprocessing:
|
|||||||
]
|
]
|
||||||
try:
|
try:
|
||||||
# connections.connect(alias=MILVUS_ALIAS, host=MILVUS_DB_HOST, port=MILVUS_PORT)
|
# 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.
|
# collection = Collection(MILVUS_TABLE_KEYPOINT) # Get an existing collection.
|
||||||
# mr = collection.upsert(data)
|
# mr = collection.upsert(data)
|
||||||
# logging.info(f"save keypoint time : {time.time() - start_time}")
|
# logging.info(f"save keypoint time : {time.time() - start_time}")
|
||||||
@@ -348,9 +358,9 @@ if __name__ == '__main__':
|
|||||||
data = {
|
data = {
|
||||||
"sketches": [
|
"sketches": [
|
||||||
{
|
{
|
||||||
"image_category": "dress",
|
"image_category": "blouse",
|
||||||
"image_id": "107903",
|
"image_id": "123123123",
|
||||||
"image_url": "aida-sys-image/images/female/dress/0628000000.jpg"
|
"image_url": "test/0628000198.jpg"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user