feat
fix minio and s3
This commit is contained in:
@@ -13,15 +13,12 @@ import io
|
||||
|
||||
from app.core.config import *
|
||||
from app.service.design.utils.design_ensemble import get_keypoint_result
|
||||
from app.service.utils.oss_client import oss_get_image, oss_upload_image
|
||||
|
||||
|
||||
class DesignPreprocessing:
|
||||
def __init__(self):
|
||||
self.minio_client = Minio(
|
||||
MINIO_URL,
|
||||
access_key=MINIO_ACCESS,
|
||||
secret_key=MINIO_SECRET,
|
||||
secure=MINIO_SECURE)
|
||||
# def __init__(self):
|
||||
# self.minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||
|
||||
# @ RunTime
|
||||
def pipeline(self, image_list):
|
||||
@@ -51,8 +48,9 @@ class DesignPreprocessing:
|
||||
|
||||
def read_image(self, image_list):
|
||||
for obj in image_list:
|
||||
file = self.minio_client.get_object(obj['image_url'].split("/", 1)[0], obj['image_url'].split("/", 1)[1]).data
|
||||
image = cv2.imdecode(np.frombuffer(file, np.uint8), 1)
|
||||
# file = self.minio_client.get_object(obj['image_url'].split("/", 1)[0], obj['image_url'].split("/", 1)[1]).data
|
||||
# image = cv2.imdecode(np.frombuffer(file, np.uint8), 1)
|
||||
image = oss_get_image(bucket=obj['image_url'].split("/", 1)[0], object_name=obj['image_url'].split("/", 1)[1], data_type="cv2")
|
||||
if len(image.shape) == 2:
|
||||
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
|
||||
elif image.shape[2] == 4: # 如果是四通道 mask
|
||||
@@ -125,7 +123,10 @@ class DesignPreprocessing:
|
||||
try:
|
||||
# 覆盖到minio
|
||||
image_bytes = cv2.imencode(".jpg", item['obj'])[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", )
|
||||
# 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", )
|
||||
bucket_name = item['image_url'].split("/", 1)[0]
|
||||
object_name = item['image_url'].split("/", 1)[1]
|
||||
oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=image_bytes)
|
||||
print(f"Object '{item['image_url'].split('/', 1)[1]}' overwritten successfully.")
|
||||
except ResponseError as err:
|
||||
print(f"Error: {err}")
|
||||
@@ -165,36 +166,76 @@ class DesignPreprocessing:
|
||||
# @ RunTime
|
||||
def composing_image(self, image_list):
|
||||
for image in image_list:
|
||||
if image['site'] == 'down':
|
||||
image_width = image['obj'].shape[1]
|
||||
waist_width = image['keypoint_result']['waistband_right'][1] - image['keypoint_result']['waistband_left'][1]
|
||||
scale = 0.4
|
||||
if waist_width / scale >= image['obj'].shape[1]:
|
||||
add_width = int((waist_width / scale - image_width) / 2)
|
||||
ret = cv2.copyMakeBorder(image['obj'], 0, 0, add_width, add_width, cv2.BORDER_CONSTANT, value=(256, 256, 256))
|
||||
if IF_DEBUG_SHOW:
|
||||
cv2.imshow("composing_image", ret)
|
||||
cv2.waitKey(0)
|
||||
image_bytes = cv2.imencode(".jpg", ret)[1].tobytes()
|
||||
image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
else:
|
||||
image_bytes = cv2.imencode(".jpg", image['obj'])[1].tobytes()
|
||||
image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
''' 比例相同 整合上下装代码'''
|
||||
image_width = image['obj'].shape[1]
|
||||
waist_width = image['keypoint_result']['waistband_right'][1] - image['keypoint_result']['waistband_left'][1]
|
||||
scale = 0.4
|
||||
if waist_width / scale >= image_width:
|
||||
add_width = int((waist_width / scale - image_width) / 2)
|
||||
ret = cv2.copyMakeBorder(image['obj'], 0, 0, add_width, add_width, cv2.BORDER_CONSTANT, value=(256, 256, 256))
|
||||
if IF_DEBUG_SHOW:
|
||||
cv2.imshow("composing_image", ret)
|
||||
cv2.waitKey(0)
|
||||
image_bytes = cv2.imencode(".jpg", ret)[1].tobytes()
|
||||
# image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
bucket_name = image['image_url'].split('/', 1)[0]
|
||||
object_name = image['image_url'].split('/', 1)[1]
|
||||
oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=image_bytes)
|
||||
image['show_image_url'] = f"{bucket_name}/{object_name}"
|
||||
else:
|
||||
scale = 0.4
|
||||
image_width = image['obj'].shape[1]
|
||||
waist_width = image['keypoint_result']['armpit_right'][1] - image['keypoint_result']['armpit_left'][1]
|
||||
if waist_width / scale >= image_width:
|
||||
add_width = int((waist_width / scale - image_width) / 2)
|
||||
ret = cv2.copyMakeBorder(image['obj'], 0, 0, add_width, add_width, cv2.BORDER_CONSTANT, value=(256, 256, 256))
|
||||
if IF_DEBUG_SHOW:
|
||||
cv2.imshow("composing_image", ret)
|
||||
cv2.waitKey(0)
|
||||
image_bytes = cv2.imencode(".jpg", ret)[1].tobytes()
|
||||
image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
else:
|
||||
image_bytes = cv2.imencode(".jpg", image['obj'])[1].tobytes()
|
||||
image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
image_bytes = cv2.imencode(".jpg", image['obj'])[1].tobytes()
|
||||
# image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
bucket_name = image['image_url'].split('/', 1)[0]
|
||||
object_name = image['image_url'].split('/', 1)[1]
|
||||
oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=image_bytes)
|
||||
image['show_image_url'] = f"{bucket_name}/{object_name}"
|
||||
|
||||
# if image['site'] == 'down':
|
||||
# image_width = image['obj'].shape[1]
|
||||
# waist_width = image['keypoint_result']['waistband_right'][1] - image['keypoint_result']['waistband_left'][1]
|
||||
# scale = 0.4
|
||||
# if waist_width / scale >= image_width:
|
||||
# add_width = int((waist_width / scale - image_width) / 2)
|
||||
# ret = cv2.copyMakeBorder(image['obj'], 0, 0, add_width, add_width, cv2.BORDER_CONSTANT, value=(256, 256, 256))
|
||||
# if IF_DEBUG_SHOW:
|
||||
# cv2.imshow("composing_image", ret)
|
||||
# cv2.waitKey(0)
|
||||
# image_bytes = cv2.imencode(".jpg", ret)[1].tobytes()
|
||||
# # image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
# bucket_name = image['image_url'].split('/', 1)[0]
|
||||
# object_name = image['image_url'].split('/', 1)[1]
|
||||
# oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=image_bytes)
|
||||
# image['show_image_url'] = f"{bucket_name}/{object_name}"
|
||||
# else:
|
||||
# image_bytes = cv2.imencode(".jpg", image['obj'])[1].tobytes()
|
||||
# # image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
# bucket_name = image['image_url'].split('/', 1)[0]
|
||||
# object_name = image['image_url'].split('/', 1)[1]
|
||||
# oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=image_bytes)
|
||||
# image['show_image_url'] = f"{bucket_name}/{object_name}"
|
||||
# else:
|
||||
# image_width = image['obj'].shape[1]
|
||||
# waist_width = image['keypoint_result']['waistband_right'][1] - image['keypoint_result']['waistband_left'][1]
|
||||
# scale = 0.4
|
||||
# if waist_width / scale >= image_width:
|
||||
# add_width = int((waist_width / scale - image_width) / 2)
|
||||
# ret = cv2.copyMakeBorder(image['obj'], 0, 0, add_width, add_width, cv2.BORDER_CONSTANT, value=(256, 256, 256))
|
||||
# if IF_DEBUG_SHOW:
|
||||
# cv2.imshow("composing_image", ret)
|
||||
# cv2.waitKey(0)
|
||||
# image_bytes = cv2.imencode(".jpg", ret)[1].tobytes()
|
||||
# # image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
# bucket_name = image['image_url'].split('/', 1)[0]
|
||||
# object_name = image['image_url'].split('/', 1)[1]
|
||||
# oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=image_bytes)
|
||||
# image['show_image_url'] = f"{bucket_name}/{object_name}"
|
||||
# else:
|
||||
# image_bytes = cv2.imencode(".jpg", image['obj'])[1].tobytes()
|
||||
# # image['show_image_url'] = f"{image['image_url'].split('/', 1)[0]}/{self.minio_client.put_object(image['image_url'].split('/', 1)[0], image['image_url'].split('/', 1)[1].replace('.', '-show.'), io.BytesIO(image_bytes), len(image_bytes), content_type='image/jpeg').object_name}"
|
||||
# bucket_name = image['image_url'].split('/', 1)[0]
|
||||
# object_name = image['image_url'].split('/', 1)[1]
|
||||
# oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=image_bytes)
|
||||
# image['show_image_url'] = f"{bucket_name}/{object_name}"
|
||||
return image_list
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user