Spaces:
Runtime error
Runtime error
jens
commited on
Commit
·
8f90f14
1
Parent(s):
f07135c
going home commit
Browse files
app.py
CHANGED
@@ -77,9 +77,7 @@ with block:
|
|
77 |
image = inputs[raw_image]
|
78 |
generated_mask, _, _ = sam.cond_pred(pts=np.array(inputs[point_coords]), lbls=np.array(inputs[point_labels]))
|
79 |
inputs[masks].append((generated_mask, inputs[text]))
|
80 |
-
return {masks_annotated_image: (image, inputs[masks])
|
81 |
-
masks: generated_mask,
|
82 |
-
cutout_idx: set()}
|
83 |
sam_decode_btn.click(on_click_sam_dencode_btn, components, [masks_annotated_image, masks, cutout_idx], queue=True)
|
84 |
#sam_sgmt_everything_btn.click(on_sam_sgmt_everything_click, components, [masks_annotated_image, masks, cutout_idx], queue=True)
|
85 |
|
|
|
77 |
image = inputs[raw_image]
|
78 |
generated_mask, _, _ = sam.cond_pred(pts=np.array(inputs[point_coords]), lbls=np.array(inputs[point_labels]))
|
79 |
inputs[masks].append((generated_mask, inputs[text]))
|
80 |
+
return {masks_annotated_image: (image, inputs[masks])}
|
|
|
|
|
81 |
sam_decode_btn.click(on_click_sam_dencode_btn, components, [masks_annotated_image, masks, cutout_idx], queue=True)
|
82 |
#sam_sgmt_everything_btn.click(on_sam_sgmt_everything_click, components, [masks_annotated_image, masks, cutout_idx], queue=True)
|
83 |
|
utils.py
CHANGED
@@ -109,3 +109,34 @@ def point_cloud(rgb_image, depth_image):
|
|
109 |
fig = px.scatter_3d(df, x='x', y='y', z='z', color='red', size_max=0.1)
|
110 |
|
111 |
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
fig = px.scatter_3d(df, x='x', y='y', z='z', color='red', size_max=0.1)
|
110 |
|
111 |
return fig
|
112 |
+
|
113 |
+
def array_PCL(rgb_image, depth_image):
|
114 |
+
FX_RGB = 5.1885790117450188e+02
|
115 |
+
FY_RGB = 5.1946961112127485e+02
|
116 |
+
CX_RGB = 3.2558244941119034e+0
|
117 |
+
CY_RGB = 2.5373616633400465e+02
|
118 |
+
FX_DEPTH = FX_RGB
|
119 |
+
FY_DEPTH = FY_RGB
|
120 |
+
CX_DEPTH = CX_RGB
|
121 |
+
CY_DEPTH = CY_RGB
|
122 |
+
height = depth_image.shape[0]
|
123 |
+
width = depth_image.shape[1]
|
124 |
+
# compute indices:
|
125 |
+
jj = np.tile(range(width), height)
|
126 |
+
ii = np.repeat(range(height), width)
|
127 |
+
|
128 |
+
# Compute constants:
|
129 |
+
xx = (jj - CX_DEPTH) / FX_DEPTH
|
130 |
+
yy = (ii - CY_DEPTH) / FY_DEPTH
|
131 |
+
|
132 |
+
# transform depth image to vector of z:
|
133 |
+
length = height * width
|
134 |
+
z = depth_image.reshape(length)
|
135 |
+
|
136 |
+
# compute point cloud
|
137 |
+
pcd = np.dstack((xx * z, yy * z, z)).reshape((length, 3))
|
138 |
+
#cam_RGB = np.apply_along_axis(np.linalg.inv(R).dot, 1, pcd) - np.linalg.inv(R).dot(T)
|
139 |
+
xx_rgb = ((rgb_image[:, 0] * FX_RGB) / rgb_image[:, 2] + CX_RGB + width / 2).astype(int).clip(0, width - 1)
|
140 |
+
yy_rgb = ((rgb_image[:, 1] * FY_RGB) / rgb_image[:, 2] + CY_RGB).astype(int).clip(0, height - 1)
|
141 |
+
colors = rgb_image[yy_rgb, xx_rgb]/255
|
142 |
+
return pcd, colors
|