Spaces:
Sleeping
Sleeping
parokshsaxena
commited on
Commit
β’
72b00c6
1
Parent(s):
e37bd67
handling landmark use case of not removing bottom part of model to convert image to standard 3x4 Aspect Ratio
Browse files
app.py
CHANGED
@@ -134,10 +134,11 @@ POSE_HEIGHT = int(HEIGHT/2) #int(HEIGHT/2)
|
|
134 |
ARM_WIDTH = "dc" # "hd" # hd -> full sleeve, dc for half sleeve
|
135 |
CATEGORY = "upper_body" # "lower_body"
|
136 |
|
|
|
137 |
def is_cropping_required(width, height):
|
138 |
-
# If aspect ratio is 1.
|
139 |
aspect_ratio = round(height/width, 2)
|
140 |
-
if aspect_ratio ==
|
141 |
return False
|
142 |
return True
|
143 |
|
@@ -157,7 +158,7 @@ def start_tryon(human_img_dict,garm_img,garment_des, background_img, is_checked,
|
|
157 |
|
158 |
|
159 |
"""
|
160 |
-
# Derive HEIGHT & WIDTH such that width is not more than 1000. This will cater to both Shein images (4160x6240) of 3
|
161 |
WIDTH, HEIGHT = human_img_orig.size
|
162 |
division_factor = math.ceil(WIDTH/1000)
|
163 |
WIDTH = int(WIDTH/division_factor)
|
@@ -174,12 +175,16 @@ def start_tryon(human_img_dict,garm_img,garment_des, background_img, is_checked,
|
|
174 |
# This will crop the image to make it Aspect Ratio of 3 x 4. And then at the end revert it back to original dimentions
|
175 |
width, height = human_img_orig.size
|
176 |
target_width = int(min(width, height * (3 / 4)))
|
177 |
-
target_height = int(min(height, width * (4 / 3)))
|
|
|
178 |
left = (width - target_width) / 2
|
179 |
-
top = (height - target_height) / 2
|
180 |
right = (width + target_width) / 2
|
181 |
-
|
|
|
|
|
|
|
182 |
cropped_img = human_img_orig.crop((left, top, right, bottom))
|
|
|
183 |
crop_size = cropped_img.size
|
184 |
human_img = cropped_img.resize((WIDTH, HEIGHT))
|
185 |
else:
|
|
|
134 |
ARM_WIDTH = "dc" # "hd" # hd -> full sleeve, dc for half sleeve
|
135 |
CATEGORY = "upper_body" # "lower_body"
|
136 |
|
137 |
+
|
138 |
def is_cropping_required(width, height):
|
139 |
+
# If aspect ratio is 1.33, which is same as standard 3x4 ( 768x1024 ), then no need to crop, else crop
|
140 |
aspect_ratio = round(height/width, 2)
|
141 |
+
if aspect_ratio == 1.33:
|
142 |
return False
|
143 |
return True
|
144 |
|
|
|
158 |
|
159 |
|
160 |
"""
|
161 |
+
# Derive HEIGHT & WIDTH such that width is not more than 1000. This will cater to both Shein images (4160x6240) of 2:3 AR and model standard images ( 768x1024 ) of 3:4 AR
|
162 |
WIDTH, HEIGHT = human_img_orig.size
|
163 |
division_factor = math.ceil(WIDTH/1000)
|
164 |
WIDTH = int(WIDTH/division_factor)
|
|
|
175 |
# This will crop the image to make it Aspect Ratio of 3 x 4. And then at the end revert it back to original dimentions
|
176 |
width, height = human_img_orig.size
|
177 |
target_width = int(min(width, height * (3 / 4)))
|
178 |
+
target_height = int(min(height, width * (4 / 3)))
|
179 |
+
|
180 |
left = (width - target_width) / 2
|
|
|
181 |
right = (width + target_width) / 2
|
182 |
+
# for Landmark, model sizes are 594x879, so we need to reduce the height. In some case the garment on the model is
|
183 |
+
# also getting removed when reducing size from bottom. So we will only reduce height from top for now
|
184 |
+
top = (height - target_height) #top = (height - target_height) / 2
|
185 |
+
bottom = height #bottom = (height + target_height) / 2
|
186 |
cropped_img = human_img_orig.crop((left, top, right, bottom))
|
187 |
+
|
188 |
crop_size = cropped_img.size
|
189 |
human_img = cropped_img.resize((WIDTH, HEIGHT))
|
190 |
else:
|