Update app.py
Browse files
app.py
CHANGED
@@ -44,12 +44,29 @@ def warp_design(design, mask, warp_scale):
|
|
44 |
|
45 |
def blend_images(base, overlay, mask):
|
46 |
"""Blends the design onto the dress using seamless cloning."""
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
if mask.dtype != np.uint8:
|
51 |
-
mask = (mask * 255).astype(np.uint8)
|
52 |
-
|
|
|
|
|
|
|
53 |
return cv2.seamlessClone(overlay, base, mask, center, cv2.NORMAL_CLONE)
|
54 |
|
55 |
def apply_design(image_path, design_path, warp_scale):
|
|
|
44 |
|
45 |
def blend_images(base, overlay, mask):
|
46 |
"""Blends the design onto the dress using seamless cloning."""
|
47 |
+
if overlay is None or mask is None:
|
48 |
+
raise ValueError("Overlay or mask is None, check segmentation and warping.")
|
49 |
+
|
50 |
+
base = np.array(base) # Ensure base is a NumPy array
|
51 |
+
overlay = np.array(overlay)
|
52 |
+
|
53 |
+
# Ensure overlay and base are 3-channel images
|
54 |
+
if len(overlay.shape) == 2:
|
55 |
+
overlay = cv2.cvtColor(overlay, cv2.COLOR_GRAY2BGR)
|
56 |
+
if len(base.shape) == 2:
|
57 |
+
base = cv2.cvtColor(base, cv2.COLOR_GRAY2BGR)
|
58 |
+
|
59 |
+
# Ensure mask is single-channel grayscale
|
60 |
+
if len(mask.shape) == 3:
|
61 |
+
mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
|
62 |
+
|
63 |
+
# Convert mask to uint8 if necessary
|
64 |
if mask.dtype != np.uint8:
|
65 |
+
mask = (mask * 255).astype(np.uint8)
|
66 |
+
|
67 |
+
# Compute center of the mask for seamless cloning
|
68 |
+
center = tuple(np.array(base.shape[:2]) // 2)
|
69 |
+
|
70 |
return cv2.seamlessClone(overlay, base, mask, center, cv2.NORMAL_CLONE)
|
71 |
|
72 |
def apply_design(image_path, design_path, warp_scale):
|