Compare commits
38 Commits
ac6f74438d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9db2f96557 | |||
| cc2404831d | |||
| 6892361050 | |||
| f0b73d5fc1 | |||
| ea7522a45d | |||
| 7543d6b346 | |||
| 3ca4003e30 | |||
| 59e8a88a01 | |||
| 3414f2c1aa | |||
| 160bf1a6b1 | |||
| a4d55fdb14 | |||
| 7f2f79d029 | |||
| 6d9e96305b | |||
| d93c50ce2b | |||
| e25f49a776 | |||
| 33b4dd4a7f | |||
| 7e48420ba7 | |||
| 09e25f423e | |||
| dcc88adfc0 | |||
| c03b7e263e | |||
| 200414e5ad | |||
| 4656eeee91 | |||
| fe25f5878b | |||
| 2cc17a1210 | |||
| be92d48abb | |||
| f8382f280f | |||
| c24862507f | |||
| e02ca351b6 | |||
| c987f498bc | |||
| 3aa8dfa0f4 | |||
| 265f4de50e | |||
| a996a1853d | |||
| 1cbd019ffd | |||
| e2a49e2f3a | |||
| 66037c94e6 | |||
| 754e8d7735 | |||
| cdaeb6daac | |||
| 863d9287dc |
@@ -7,7 +7,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
REMOTE_DEPLOY_PATH: /workspace/AiDA_Workspace/Python_Server_Workspace/Prod
|
||||
REMOTE_DEPLOY_PATH: /workspace/AiDA_Workspace/Python_Server_Workspace/AiDA_Prod
|
||||
|
||||
steps:
|
||||
- name: 1.检出代码
|
||||
|
||||
@@ -36,7 +36,7 @@ class Settings(BaseSettings):
|
||||
|
||||
# --- mysql 配置信息 ---
|
||||
MYSQL_HOST: str = Field(default='', description="")
|
||||
MYSQL_PORT: int = Field(default='', description="")
|
||||
MYSQL_PORT: int = Field(default=3306, description="")
|
||||
MYSQL_USER: str = Field(default='', description="")
|
||||
MYSQL_PASSWORD: str = Field(default='', description="")
|
||||
MYSQL_DB: str = Field(default='', description="")
|
||||
|
||||
@@ -8,9 +8,9 @@ class SAMRequestModel(BaseModel):
|
||||
object_name: str = Field(..., description="minio object name ")
|
||||
image_path: str = Field(..., description="图片路径,必填字段")
|
||||
type: str = Field(..., description="推理类型,必填字段")
|
||||
points: Optional[List[List[float]]] = None
|
||||
labels: Optional[List[int]] = None
|
||||
box: Optional[List[int]] = None
|
||||
points: Optional[List[List[float]]] | None = None
|
||||
labels: Optional[List[int]] | None = None
|
||||
box: Optional[List[int]] | None = None
|
||||
|
||||
|
||||
class DesignModel(BaseModel):
|
||||
|
||||
@@ -35,6 +35,13 @@ class GenerateSingleLogoImageModel(BaseModel):
|
||||
seed: str
|
||||
|
||||
|
||||
class GenerateSloganImageModel(BaseModel):
|
||||
num_point: int
|
||||
tasks_id: str
|
||||
prompt: str
|
||||
image_url: str
|
||||
|
||||
|
||||
class GenerateProductImageModel(BaseModel):
|
||||
tasks_id: str
|
||||
prompt: str
|
||||
@@ -43,6 +50,13 @@ class GenerateProductImageModel(BaseModel):
|
||||
product_type: str
|
||||
|
||||
|
||||
class Flux2ToProductImgModel(BaseModel):
|
||||
tasks_id: str
|
||||
prompt: str
|
||||
image_path: str
|
||||
infer_step: int | None = None
|
||||
|
||||
|
||||
class GenerateRelightImageModel(BaseModel):
|
||||
tasks_id: str
|
||||
prompt: str
|
||||
|
||||
@@ -27,7 +27,7 @@ class NoSegPrintPainting:
|
||||
# 获取平铺 + 旋转 的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['pattern_image'] = result['no_seg_sketch_overall']
|
||||
# result['pattern_image'] = result['no_seg_sketch_overall']
|
||||
|
||||
if single_print:
|
||||
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_pattern = (int(dim_max * print_['scale'] / 5), int(dim_max * print_['scale'] / 5))
|
||||
gap = print_dict.get('gap', [[0, 0]])[0]
|
||||
painting_dict['tile_print'] = tile_image(pattern=print_['image'],
|
||||
dim=dim_pattern,
|
||||
gap_x=gap[0],
|
||||
gap_y=gap[1],
|
||||
canvas_h=painting_dict['dim_image_h'],
|
||||
canvas_w=painting_dict['dim_image_w'],
|
||||
location=painting_dict['location'],
|
||||
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['tile_print'], painting_dict['mask_inv_print'] = tile_image(pattern=print_['image'],
|
||||
mask=print_['mask'],
|
||||
dim=dim_pattern,
|
||||
gap_x=gap[0],
|
||||
gap_y=gap[1],
|
||||
canvas_h=painting_dict['dim_image_h'],
|
||||
canvas_w=painting_dict['dim_image_w'],
|
||||
location=painting_dict['location'],
|
||||
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
|
||||
|
||||
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")
|
||||
# 判断图片格式,如果是RGBA 则贴在一张纯白图片上 防止透明转黑
|
||||
if image.mode == "RGBA":
|
||||
mask_pil = image.split()[3]
|
||||
new_background = Image.new('RGB', image.size, (255, 255, 255))
|
||||
new_background.paste(image, mask=image.split()[3])
|
||||
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['mask'] = cv2.threshold(np.array(mask_pil), 127, 255, cv2.THRESH_BINARY)[1]
|
||||
|
||||
return print_dict
|
||||
|
||||
def crop_image(self, image, image_size_h, image_size_w, location, print_shape):
|
||||
@@ -408,9 +415,12 @@ class NoSegPrintPainting:
|
||||
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 间距平铺印花,并支持旋转
|
||||
【修改版】以被平铺图案的【中心】作为平铺基准点
|
||||
|
||||
:param location: [[center_y, center_x]] → 第一个图案中心的坐标
|
||||
:param angle: 旋转角度 (度数, 逆时针)
|
||||
"""
|
||||
# 1. 确保输入是 RGBA
|
||||
@@ -422,35 +432,54 @@ def tile_image(pattern, dim, gap_x, gap_y, canvas_h, canvas_w, location, angle=0
|
||||
rotated_p = rotate_image(resized_p, angle)
|
||||
p_h, p_w = rotated_p.shape[:2]
|
||||
|
||||
# 3. 创建透明单元格
|
||||
cell_h, cell_w = p_h + gap_y, p_w + gap_x
|
||||
# 3. 创建透明单元格(图案放在单元格中心)
|
||||
cell_h = p_h + gap_y
|
||||
cell_w = p_w + gap_x
|
||||
|
||||
unit_cell = np.zeros((cell_h, cell_w, 4), dtype=np.uint8)
|
||||
unit_cell[:p_h, :p_w, :] = rotated_p
|
||||
|
||||
# 计算图案在单元格中的左上角位置(让图案居中)
|
||||
start_y = (cell_h - p_h) // 2
|
||||
start_x = (cell_w - p_w) // 2
|
||||
unit_cell[start_y:start_y + p_h, start_x:start_x + p_w, :] = rotated_p
|
||||
|
||||
# 4. 执行平铺
|
||||
tiles_y = (canvas_h // cell_h) + 2
|
||||
tiles_x = (canvas_w // cell_w) + 2
|
||||
tiles_y = (canvas_h // cell_h) + 3 # 多加一点余量更安全
|
||||
tiles_x = (canvas_w // cell_w) + 3
|
||||
full_tiled = np.tile(unit_cell, (tiles_y, tiles_x, 1))
|
||||
|
||||
# 5. 裁剪平铺层
|
||||
offset_x = int(location[0][1] % cell_w)
|
||||
offset_y = int(location[0][0] % cell_h)
|
||||
# 5. 计算偏移(关键修改:以中心为基准)
|
||||
center_y, center_x = location[0][0], location[0][1] # 第一个图案的中心位置
|
||||
|
||||
# 计算从哪个位置开始裁剪,才能让中心落在指定坐标
|
||||
offset_y = int((center_y - (p_h // 2)) % cell_h)
|
||||
offset_x = int((center_x - (p_w // 2)) % cell_w)
|
||||
|
||||
tiled_layer = full_tiled[offset_y: offset_y + canvas_h,
|
||||
offset_x: offset_x + canvas_w]
|
||||
|
||||
# 6. 创建纯白色背景并合成
|
||||
# 创建一个纯白色的 BGR 画布
|
||||
# 6. 创建纯白色背景并合成(保持你原来的风格)
|
||||
white_background = np.full((canvas_h, canvas_w, 3), 255, dtype=np.uint8)
|
||||
|
||||
# 分离平铺层的颜色通道和 Alpha 通道
|
||||
tiled_bgr = tiled_layer[:, :, :3]
|
||||
alpha_mask = tiled_layer[:, :, 3] / 255.0 # 归一化到 0-1
|
||||
alpha_mask = cv2.merge([alpha_mask, alpha_mask, alpha_mask]) # 扩展到 3 通道
|
||||
alpha_mask = tiled_layer[:, :, 3] / 255.0
|
||||
alpha_mask = cv2.merge([alpha_mask, alpha_mask, alpha_mask])
|
||||
|
||||
# 执行 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 ======================
|
||||
# Mask 也同样居中处理
|
||||
resized_mask = cv2.resize(mask, dim, interpolation=cv2.INTER_NEAREST)
|
||||
rotated_mask = rotate_image(resized_mask, angle) # 注意:mask也需要旋转
|
||||
|
||||
unit_mask = np.zeros((cell_h, cell_w), dtype=np.uint8)
|
||||
unit_mask[start_y:start_y + p_h, start_x:start_x + p_w] = rotated_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):
|
||||
|
||||
@@ -41,7 +41,7 @@ class PrintPainting:
|
||||
if overall_print['print_path_list']:
|
||||
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]}
|
||||
result['print_image'] = result['pattern_image']
|
||||
result['print_image'] = result['pattern_image'].copy()
|
||||
# 获取平铺 + 旋转 的overall print
|
||||
painting_dict = self.painting_collection(painting_dict, overall_print)
|
||||
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_pattern = (int(dim_max * print_['scale'] / 5), int(dim_max * print_['scale'] / 5))
|
||||
gap = print_dict.get('gap', [[0, 0]])[0]
|
||||
painting_dict['tile_print'] = tile_image(pattern=print_['image'],
|
||||
dim=dim_pattern,
|
||||
gap_x=gap[0],
|
||||
gap_y=gap[1],
|
||||
canvas_h=painting_dict['dim_image_h'],
|
||||
canvas_w=painting_dict['dim_image_w'],
|
||||
location=painting_dict['location'],
|
||||
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['tile_print'], painting_dict['mask_inv_print'] = tile_image(pattern=print_['image'],
|
||||
mask=print_['mask'],
|
||||
dim=dim_pattern,
|
||||
gap_x=gap[0],
|
||||
gap_y=gap[1],
|
||||
canvas_h=painting_dict['dim_image_h'],
|
||||
canvas_w=painting_dict['dim_image_w'],
|
||||
location=painting_dict['location'],
|
||||
angle=int(print_.get('print_angle_list', [0])[0]))
|
||||
return painting_dict
|
||||
|
||||
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")
|
||||
# 判断图片格式,如果是RGBA 则贴在一张纯白图片上 防止透明转黑
|
||||
if image.mode == "RGBA":
|
||||
mask_pil = image.split()[3]
|
||||
new_background = Image.new('RGB', image.size, (255, 255, 255))
|
||||
new_background.paste(image, mask=image.split()[3])
|
||||
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['mask'] = cv2.threshold(np.array(mask_pil), 127, 255, cv2.THRESH_BINARY)[1]
|
||||
|
||||
return print_dict
|
||||
|
||||
def crop_image(self, image, image_size_h, image_size_w, location, print_shape):
|
||||
@@ -471,9 +476,12 @@ class PrintPainting:
|
||||
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 间距平铺印花,并支持旋转
|
||||
【修改版】以被平铺图案的【中心】作为平铺基准点
|
||||
|
||||
:param location: [[center_y, center_x]] → 第一个图案中心的坐标
|
||||
:param angle: 旋转角度 (度数, 逆时针)
|
||||
"""
|
||||
# 1. 确保输入是 RGBA
|
||||
@@ -485,35 +493,54 @@ def tile_image(pattern, dim, gap_x, gap_y, canvas_h, canvas_w, location, angle=0
|
||||
rotated_p = rotate_image(resized_p, angle)
|
||||
p_h, p_w = rotated_p.shape[:2]
|
||||
|
||||
# 3. 创建透明单元格
|
||||
cell_h, cell_w = p_h + gap_y, p_w + gap_x
|
||||
# 3. 创建透明单元格(图案放在单元格中心)
|
||||
cell_h = p_h + gap_y
|
||||
cell_w = p_w + gap_x
|
||||
|
||||
unit_cell = np.zeros((cell_h, cell_w, 4), dtype=np.uint8)
|
||||
unit_cell[:p_h, :p_w, :] = rotated_p
|
||||
|
||||
# 计算图案在单元格中的左上角位置(让图案居中)
|
||||
start_y = (cell_h - p_h) // 2
|
||||
start_x = (cell_w - p_w) // 2
|
||||
unit_cell[start_y:start_y + p_h, start_x:start_x + p_w, :] = rotated_p
|
||||
|
||||
# 4. 执行平铺
|
||||
tiles_y = (canvas_h // cell_h) + 2
|
||||
tiles_x = (canvas_w // cell_w) + 2
|
||||
tiles_y = (canvas_h // cell_h) + 3 # 多加一点余量更安全
|
||||
tiles_x = (canvas_w // cell_w) + 3
|
||||
full_tiled = np.tile(unit_cell, (tiles_y, tiles_x, 1))
|
||||
|
||||
# 5. 裁剪平铺层
|
||||
offset_x = int(location[0][1] % cell_w)
|
||||
offset_y = int(location[0][0] % cell_h)
|
||||
# 5. 计算偏移(关键修改:以中心为基准)
|
||||
center_y, center_x = location[0][0], location[0][1] # 第一个图案的中心位置
|
||||
|
||||
# 计算从哪个位置开始裁剪,才能让中心落在指定坐标
|
||||
offset_y = int((center_y - (p_h // 2)) % cell_h)
|
||||
offset_x = int((center_x - (p_w // 2)) % cell_w)
|
||||
|
||||
tiled_layer = full_tiled[offset_y: offset_y + canvas_h,
|
||||
offset_x: offset_x + canvas_w]
|
||||
|
||||
# 6. 创建纯白色背景并合成
|
||||
# 创建一个纯白色的 BGR 画布
|
||||
# 6. 创建纯白色背景并合成(保持你原来的风格)
|
||||
white_background = np.full((canvas_h, canvas_w, 3), 255, dtype=np.uint8)
|
||||
|
||||
# 分离平铺层的颜色通道和 Alpha 通道
|
||||
tiled_bgr = tiled_layer[:, :, :3]
|
||||
alpha_mask = tiled_layer[:, :, 3] / 255.0 # 归一化到 0-1
|
||||
alpha_mask = cv2.merge([alpha_mask, alpha_mask, alpha_mask]) # 扩展到 3 通道
|
||||
alpha_mask = tiled_layer[:, :, 3] / 255.0
|
||||
alpha_mask = cv2.merge([alpha_mask, alpha_mask, alpha_mask])
|
||||
|
||||
# 执行 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 ======================
|
||||
# Mask 也同样居中处理
|
||||
resized_mask = cv2.resize(mask, dim, interpolation=cv2.INTER_NEAREST)
|
||||
rotated_mask = rotate_image(resized_mask, angle) # 注意:mask也需要旋转
|
||||
|
||||
unit_mask = np.zeros((cell_h, cell_w), dtype=np.uint8)
|
||||
unit_mask[start_y:start_y + p_h, start_x:start_x + p_w] = rotated_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):
|
||||
|
||||
@@ -342,82 +342,33 @@ def update_base_size_priority(layers):
|
||||
|
||||
|
||||
def transpose_rotate(layer, image):
|
||||
"""
|
||||
融合镜像(transpose)和旋转(rotate)逻辑,计算实际旋转角度后执行图像变换,
|
||||
并调整粘贴位置以保持视觉中心一致
|
||||
# transpose[0]是左右 transpose[1]是上下
|
||||
transpose = layer.get('transpose', [1, 1]) # 默认为1, 1代表不镜像
|
||||
|
||||
参数:
|
||||
layer: 包含transpose、rotate、adaptive_position等属性的字典
|
||||
image: PIL Image对象,待处理的图像
|
||||
|
||||
返回:
|
||||
tuple: (处理后的Image对象, 新的粘贴坐标(x, y))
|
||||
"""
|
||||
# 获取镜像状态(transpose[0]=左右,transpose[1]=上下;1=正常,-1=镜像)
|
||||
transpose = layer.get('transpose', [1, 1])
|
||||
is_mirrored_x = transpose[0] # 左右镜像状态
|
||||
is_mirrored_y = transpose[1] # 上下镜像状态
|
||||
|
||||
# 获取原始旋转角度和粘贴位置
|
||||
original_rotate = layer.get('rotate', 0)
|
||||
rotate = layer.get('rotate', 0)
|
||||
paste_x, paste_y = layer['adaptive_position'][1], layer['adaptive_position'][0]
|
||||
original_w = image.width
|
||||
original_h = image.height
|
||||
# transpose左右是1 上下是-1
|
||||
if transpose[0] != 1:
|
||||
# 左右
|
||||
image = image.transpose(0)
|
||||
|
||||
# ------------------- 核心修改:计算实际旋转角度 -------------------
|
||||
# 结合镜像状态,计算需要实际执行的旋转角度
|
||||
actual_rotate = calculate_actual_rotate(original_rotate, is_mirrored_x, is_mirrored_y)
|
||||
# ------------------- 执行镜像变换 -------------------
|
||||
# 左右镜像(transpose[0] != 1 即-1,表示镜像)
|
||||
if is_mirrored_x != 1:
|
||||
image = image.transpose(0) # 假设transpose(0)对应左右翻转(需匹配你的PIL版本)
|
||||
if transpose[1] != 1:
|
||||
# 上下
|
||||
image = image.transpose(1)
|
||||
|
||||
# 上下镜像(transpose[1] != 1 即-1,表示镜像)
|
||||
if is_mirrored_y != 1:
|
||||
image = image.transpose(1) # 假设transpose(1)对应上下翻转
|
||||
|
||||
# ------------------- 执行旋转并调整粘贴位置 -------------------
|
||||
if actual_rotate != 0: # 只有实际旋转角度非0时才执行旋转
|
||||
# 注意:原代码中是rotate(-rotate),这里同步调整符号
|
||||
image = image.rotate(-actual_rotate, expand=True)
|
||||
|
||||
# 计算粘贴位置以保持视觉中心一致
|
||||
# 原位置的中心点
|
||||
if rotate:
|
||||
image = image.rotate(-rotate, expand=True)
|
||||
# 4. 计算粘贴位置以保持视觉中心一致
|
||||
# 原本 (15, 36) 是 288*288 的左上角,我们计算其中心点
|
||||
target_center_x = paste_x + original_w // 2
|
||||
target_center_y = paste_y + original_h // 2
|
||||
|
||||
# 旋转后图像的新尺寸
|
||||
# 获取旋转后图像的新尺寸
|
||||
new_w, new_h = image.size
|
||||
|
||||
# 新的左上角坐标(保证中心不变)
|
||||
# 计算新的左上角坐标,使得旋转后的图像中心依然在原定的中心位置
|
||||
paste_x = target_center_x - new_w // 2
|
||||
paste_y = target_center_y - new_h // 2
|
||||
|
||||
return image, (paste_x, paste_y)
|
||||
|
||||
|
||||
def calculate_actual_rotate(before_rotate, is_mirrored_x, is_mirrored_y):
|
||||
"""
|
||||
根据X/Y轴镜像状态计算实际的旋转角度,并标准化到0-360度
|
||||
|
||||
参数:
|
||||
before_rotate: 原始旋转角度(数值类型)
|
||||
is_mirrored_x: X轴镜像状态,-1表示镜像,1表示正常
|
||||
is_mirrored_y: Y轴镜像状态,-1表示镜像,1表示正常
|
||||
|
||||
返回:
|
||||
float/int: 标准化后的实际旋转角度(0-360度)
|
||||
"""
|
||||
actual_rotate = before_rotate
|
||||
|
||||
# 根据镜像状态调整旋转角度
|
||||
if is_mirrored_x == -1 and is_mirrored_y == 1:
|
||||
actual_rotate = -before_rotate
|
||||
elif is_mirrored_x == 1 and is_mirrored_y == -1:
|
||||
actual_rotate = -before_rotate
|
||||
# elif is_mirrored_x == -1 and is_mirrored_y == -1:
|
||||
# actual_rotate = before_rotate + 180
|
||||
|
||||
# 角度标准化到0-360度
|
||||
normalized_rotate = ((actual_rotate % 360) + 360) % 360
|
||||
return normalized_rotate
|
||||
return image, (paste_x, paste_y)
|
||||
@@ -104,7 +104,7 @@ def get_translation_from_llama3(text):
|
||||
# 创建请求的负载 translator是自定义的翻译模型
|
||||
payload = {
|
||||
"model": "AiDA-translator:latest",
|
||||
"prompt": f"[{text}]",
|
||||
"prompt": text,
|
||||
"stream": False
|
||||
}
|
||||
# 将负载转换为 JSON 格式
|
||||
@@ -180,7 +180,7 @@ def get_prompt_from_image(image_path, text):
|
||||
|
||||
def main():
|
||||
"""Main function"""
|
||||
text = get_translation_from_llama3("[火焰]")
|
||||
text = get_translation_from_llama3("火焰")
|
||||
print(text)
|
||||
|
||||
|
||||
|
||||
@@ -11,4 +11,10 @@ services:
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- ./seg_cache:/seg_cache
|
||||
ports:
|
||||
- "${SERVE_PORT}:80"
|
||||
- "${SERVE_PORT}:80"
|
||||
networks:
|
||||
- aida_app_net
|
||||
networks:
|
||||
aida_app_net:
|
||||
external: true
|
||||
name: aida_app_net
|
||||
Reference in New Issue
Block a user