Update app.py
Browse files
app.py
CHANGED
@@ -12,9 +12,9 @@ def dummy_warmup():
|
|
12 |
|
13 |
import numpy as np
|
14 |
import gradio as gr
|
15 |
-
|
16 |
# import trimesh
|
17 |
-
|
18 |
# from utils.geometry import compute_pointmap
|
19 |
# import os, shutil
|
20 |
import cv2
|
@@ -177,24 +177,24 @@ import cv2
|
|
177 |
# output = moge_model.infer(input_img_torch).cpu()
|
178 |
# return output
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
#
|
183 |
-
|
184 |
-
|
185 |
-
#
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
#
|
190 |
-
|
191 |
-
|
192 |
-
#
|
193 |
-
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
|
199 |
@GPU(duration = 180)
|
200 |
def process_image(input_img):
|
@@ -205,7 +205,7 @@ def process_image(input_img):
|
|
205 |
rotated = True
|
206 |
input_img = cv2.resize(input_img, (640, 480))
|
207 |
mask, rgb = mask_rembg(input_img)
|
208 |
-
depth_dict = depth_moge(input_img)
|
209 |
if os.path.exists(outdir):
|
210 |
shutil.rmtree(outdir)
|
211 |
os.makedirs(outdir)
|
|
|
12 |
|
13 |
import numpy as np
|
14 |
import gradio as gr
|
15 |
+
import rembg
|
16 |
# import trimesh
|
17 |
+
from moge.model.v1 import MoGeModel
|
18 |
# from utils.geometry import compute_pointmap
|
19 |
# import os, shutil
|
20 |
import cv2
|
|
|
177 |
# output = moge_model.infer(input_img_torch).cpu()
|
178 |
# return output
|
179 |
|
180 |
+
@GPU(duration = 180)
|
181 |
+
def mask_rembg(input_img):
|
182 |
+
#masked_img = rembg.remove(input_img,)
|
183 |
+
output_img = rembg.remove(input_img, alpha_matting=False, post_process_mask=True)
|
184 |
+
|
185 |
+
# Convert to NumPy array
|
186 |
+
output_np = np.array(output_img)
|
187 |
+
alpha = output_np[..., 3]
|
188 |
+
|
189 |
+
# Step 2: Erode the alpha mask to shrink object slightly
|
190 |
+
kernel = np.ones((3, 3), np.uint8) # Adjust size for aggressiveness
|
191 |
+
eroded_alpha = cv2.erode(alpha, kernel, iterations=1)
|
192 |
+
# Step 3: Replace alpha channel
|
193 |
+
output_np[..., 3] = eroded_alpha
|
194 |
|
195 |
+
mask = output_np[:,:,-1] >= 128
|
196 |
+
rgb = output_np[:,:,:3]
|
197 |
+
return mask, rgb
|
198 |
|
199 |
@GPU(duration = 180)
|
200 |
def process_image(input_img):
|
|
|
205 |
rotated = True
|
206 |
input_img = cv2.resize(input_img, (640, 480))
|
207 |
mask, rgb = mask_rembg(input_img)
|
208 |
+
# depth_dict = depth_moge(input_img)
|
209 |
if os.path.exists(outdir):
|
210 |
shutil.rmtree(outdir)
|
211 |
os.makedirs(outdir)
|