Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -70,19 +70,25 @@ def fit_design_to_tshirt(design_image, mask):
|
|
70 |
contours, _ = cv2.findContours(mask_np, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
71 |
|
72 |
if contours:
|
|
|
73 |
c = max(contours, key=cv2.contourArea)
|
74 |
x, y, w, h = cv2.boundingRect(c)
|
75 |
-
|
76 |
-
#
|
|
|
|
|
|
|
77 |
design_resized = design_image.resize((w, h), Image.Resampling.LANCZOS)
|
78 |
|
|
|
79 |
canvas = Image.new("RGBA", mask.size, (0, 0, 0, 0))
|
80 |
canvas.paste(design_resized, (x, y), design_resized)
|
|
|
81 |
return canvas
|
82 |
else:
|
83 |
print("No contour found on the mask.")
|
84 |
return design_image
|
85 |
-
|
86 |
# ---------- Step 5: Overlay Design ----------
|
87 |
def overlay_design(cloth_image, design_image):
|
88 |
mask = get_tshirt_mask(cloth_image)
|
|
|
70 |
contours, _ = cv2.findContours(mask_np, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
71 |
|
72 |
if contours:
|
73 |
+
# Largest contour represents the T-shirt
|
74 |
c = max(contours, key=cv2.contourArea)
|
75 |
x, y, w, h = cv2.boundingRect(c)
|
76 |
+
|
77 |
+
# Log measurements of the T-shirt area
|
78 |
+
print(f"T-shirt Area Detected at (x: {x}, y: {y}), Width: {w}px, Height: {h}px")
|
79 |
+
|
80 |
+
# Resize design to fit within the T-shirt area
|
81 |
design_resized = design_image.resize((w, h), Image.Resampling.LANCZOS)
|
82 |
|
83 |
+
# Overlay design on a transparent canvas of the same size
|
84 |
canvas = Image.new("RGBA", mask.size, (0, 0, 0, 0))
|
85 |
canvas.paste(design_resized, (x, y), design_resized)
|
86 |
+
|
87 |
return canvas
|
88 |
else:
|
89 |
print("No contour found on the mask.")
|
90 |
return design_image
|
91 |
+
|
92 |
# ---------- Step 5: Overlay Design ----------
|
93 |
def overlay_design(cloth_image, design_image):
|
94 |
mask = get_tshirt_mask(cloth_image)
|