Spaces:
Runtime error
Runtime error
s194649
commited on
Commit
·
daeee36
1
Parent(s):
d2d76c9
fix
Browse files- app.py +6 -0
- inference.py +21 -1
app.py
CHANGED
@@ -33,6 +33,12 @@ with block:
|
|
33 |
|
34 |
# UI
|
35 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
with gr.Row():
|
37 |
with gr.Column():
|
38 |
input_image = gr.Image(label='Input', type='pil', tool=None) # mirror_webcam = False
|
|
|
33 |
|
34 |
# UI
|
35 |
with gr.Column():
|
36 |
+
gr.Markdown(
|
37 |
+
'''# Segment Anything!🚀
|
38 |
+
The Segment Anything Model (SAM) produces high quality object masks from input prompts such as points or boxes, and it can be used to generate masks for all objects in an image. More information can be found in [**Official Project**](https://segment-anything.com/).
|
39 |
+
[](https://huggingface.co/spaces/AIBoy1993/segment_anything_webui?duplicate=true)
|
40 |
+
'''
|
41 |
+
)
|
42 |
with gr.Row():
|
43 |
with gr.Column():
|
44 |
input_image = gr.Image(label='Input', type='pil', tool=None) # mirror_webcam = False
|
inference.py
CHANGED
@@ -10,7 +10,27 @@ import open3d as o3d
|
|
10 |
import pandas as pd
|
11 |
import plotly.express as px
|
12 |
import matplotlib.pyplot as plt
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
class DepthPredictor:
|
16 |
def __init__(self):
|
|
|
10 |
import pandas as pd
|
11 |
import plotly.express as px
|
12 |
import matplotlib.pyplot as plt
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
def PCL(mask, depth):
|
17 |
+
assert mask.shape == depth.shape
|
18 |
+
assert type(mask) == np.ndarray
|
19 |
+
assert type(depth) == np.ndarray
|
20 |
+
rgb_mask = np.zeros((mask.shape[0], mask.shape[1], 3))
|
21 |
+
rgb_mask[mask] = (1.0, 0.0, 0.0)
|
22 |
+
depth_o3d = o3d.geometry.Image(depth)
|
23 |
+
image_o3d = o3d.geometry.Image(mask)
|
24 |
+
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(image_o3d, depth_o3d, convert_rgb_to_intensity=False)
|
25 |
+
# Step 3: Create a PointCloud from the RGBD image
|
26 |
+
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, o3d.camera.PinholeCameraIntrinsic(o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))
|
27 |
+
# Step 4: Convert PointCloud data to a NumPy array
|
28 |
+
points = np.asarray(pcd.points)
|
29 |
+
colors = np.asarray(pcd.colors)
|
30 |
+
mask = (colors[:, 0] == 1.0)
|
31 |
+
points = points[mask]
|
32 |
+
colors = colors[mask]
|
33 |
+
return points, colors
|
34 |
|
35 |
class DepthPredictor:
|
36 |
def __init__(self):
|