Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
|
@@ -57,21 +57,25 @@ def run_sam(image, predictor, selected_points):
|
|
| 57 |
调用 SAM 模型进行分割。
|
| 58 |
"""
|
| 59 |
print(image.shape)
|
| 60 |
-
print(
|
|
|
|
| 61 |
predictor.set_image(image)
|
| 62 |
if len(selected_points) == 0:
|
| 63 |
return [], None
|
| 64 |
-
input_points = [p for p in selected_points]
|
| 65 |
-
input_labels = [1 for _ in range(len(selected_points))]
|
|
|
|
|
|
|
| 66 |
print(input_points)
|
| 67 |
print(input_labels)
|
| 68 |
masks, _, _ = predictor.predict(
|
| 69 |
-
point_coords=
|
| 70 |
-
point_labels=
|
| 71 |
-
multimask_output=
|
| 72 |
)
|
| 73 |
print(masks.shape, np.unique(masks))
|
| 74 |
-
|
|
|
|
| 75 |
return visible_mask
|
| 76 |
|
| 77 |
def apply_mask_overlay(image, mask):
|
|
|
|
| 57 |
调用 SAM 模型进行分割。
|
| 58 |
"""
|
| 59 |
print(image.shape)
|
| 60 |
+
print(image[0,0,:])
|
| 61 |
+
print(np.unique(image))
|
| 62 |
predictor.set_image(image)
|
| 63 |
if len(selected_points) == 0:
|
| 64 |
return [], None
|
| 65 |
+
# input_points = [p for p in selected_points]
|
| 66 |
+
# input_labels = [1 for _ in range(len(selected_points))]
|
| 67 |
+
input_points = np.array([[210, 300]])
|
| 68 |
+
input_labels = np.array([1])
|
| 69 |
print(input_points)
|
| 70 |
print(input_labels)
|
| 71 |
masks, _, _ = predictor.predict(
|
| 72 |
+
point_coords=input_points,
|
| 73 |
+
point_labels=input_labels,
|
| 74 |
+
multimask_output=True, # 单对象输出
|
| 75 |
)
|
| 76 |
print(masks.shape, np.unique(masks))
|
| 77 |
+
best_mask = masks[0]
|
| 78 |
+
visible_mask = 255 * best_mask.astype(np.uint8)
|
| 79 |
return visible_mask
|
| 80 |
|
| 81 |
def apply_mask_overlay(image, mask):
|