Zuii commited on
Commit
2f48c46
Β·
verified Β·
1 Parent(s): d68599b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -14
app.py CHANGED
@@ -53,32 +53,41 @@ def tryon(person_img, cloth_img, seed, random_seed):
53
  if random_seed:
54
  seed = random.randint(0, 1000000)
55
 
56
- # πŸ”΅ Convert images to RGB (keeps the blue tint glitch!)
57
- person_img = cv2.cvtColor(person_img, cv2.COLOR_BGR2RGB)
58
- cloth_img = cv2.cvtColor(cloth_img, cv2.COLOR_BGR2RGB)
 
59
 
60
- # βœ‚οΈ Resize both images to 256x256
61
- person_img = cv2.resize(person_img, (256, 256))
62
- cloth_img = cv2.resize(cloth_img, (256, 256))
63
 
64
- try:
65
- # πŸ”₯ Blend garment onto person (simple overlay β€” still has blue tint)
 
 
 
66
  output_img = person_img.copy()
67
  h, w, _ = person_img.shape
68
- g_h, g_w, _ = cloth_img.shape
69
 
70
- # Position the garment roughly on the torso (manual offset)
71
  x_offset = (w - g_w) // 2
72
  y_offset = int(h * 0.35)
73
 
74
- # βœ… Ensure garment fits inside the person image
75
  if y_offset + g_h > h or x_offset + g_w > w:
76
  raise ValueError("❗ Garment image is too large for the person image!")
77
 
78
- # πŸ› οΈ Add garment onto person (no transparency support β€” raw overlay)
79
- output_img[y_offset:y_offset + g_h, x_offset:x_offset + g_w] = cloth_img
 
 
 
 
 
 
 
80
 
81
- return output_img, seed, "βœ… Success (Blue tint + Garment added)"
82
 
83
  except Exception as e:
84
  print(f"❌ Error in tryon function: {e}")
@@ -86,6 +95,7 @@ def tryon(person_img, cloth_img, seed, random_seed):
86
 
87
 
88
 
 
89
  # πŸ”§ Paths for examples
90
  example_path = os.path.join(os.path.dirname(__file__), "assets")
91
 
 
53
  if random_seed:
54
  seed = random.randint(0, 1000000)
55
 
56
+ try:
57
+ # βœ… Convert images to RGB (fixing blue tint)
58
+ person_img = cv2.cvtColor(person_img, cv2.COLOR_BGR2RGB)
59
+ cloth_img = cv2.cvtColor(cloth_img, cv2.COLOR_BGR2RGB)
60
 
61
+ # βœ‚οΈ Resize both images to 256x256 (keep consistent sizes)
62
+ person_img = cv2.resize(person_img, (256, 256))
 
63
 
64
+ # βœ… Resize garment to fit person size
65
+ g_h, g_w = person_img.shape[:2]
66
+ cloth_img = cv2.resize(cloth_img, (g_w, g_h))
67
+
68
+ # πŸ”₯ Blend garment onto person (centered overlay)
69
  output_img = person_img.copy()
70
  h, w, _ = person_img.shape
 
71
 
72
+ # Center garment on the torso (adjust the offset if needed)
73
  x_offset = (w - g_w) // 2
74
  y_offset = int(h * 0.35)
75
 
76
+ # βœ… Ensure garment fits the person image
77
  if y_offset + g_h > h or x_offset + g_w > w:
78
  raise ValueError("❗ Garment image is too large for the person image!")
79
 
80
+ # πŸ› οΈ Overlay garment on the person (with transparency support)
81
+ alpha = 0.7 # Adjust transparency level (0 = invisible, 1 = solid)
82
+ output_img[y_offset:y_offset + g_h, x_offset:x_offset + g_w] = cv2.addWeighted(
83
+ person_img[y_offset:y_offset + g_h, x_offset:x_offset + g_w],
84
+ 1 - alpha,
85
+ cloth_img,
86
+ alpha,
87
+ 0
88
+ )
89
 
90
+ return output_img, seed, "βœ… Success (Blue tint removed + Garment added)"
91
 
92
  except Exception as e:
93
  print(f"❌ Error in tryon function: {e}")
 
95
 
96
 
97
 
98
+
99
  # πŸ”§ Paths for examples
100
  example_path = os.path.join(os.path.dirname(__file__), "assets")
101