Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,7 +29,7 @@ def get_point(point_type, tracking_points, trackings_input_label, first_frame_pa
|
|
| 29 |
transparent_layer = np.zeros((h, w, 4))
|
| 30 |
for index, track in enumerate(tracking_points.value):
|
| 31 |
if trackings_input_label.value[index] == 1:
|
| 32 |
-
cv2.circle(transparent_layer, track, 20, (0,
|
| 33 |
else:
|
| 34 |
cv2.circle(transparent_layer, track, 20, (255, 0, 0, 255), -1)
|
| 35 |
|
|
@@ -98,23 +98,19 @@ def show_masks(image, masks, scores, point_coords=None, box_coords=None, input_l
|
|
| 98 |
|
| 99 |
plt.close() # Close the figure to free up memory
|
| 100 |
|
| 101 |
-
# ---- Separate Mask Image ----
|
| 102 |
-
|
| 103 |
-
mask_image = np.zeros_like(image, dtype=np.uint8)
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
plt.gca().xaxis.set_major_locator(plt.NullLocator())
|
| 113 |
-
plt.gca().yaxis.set_major_locator(plt.NullLocator())
|
| 114 |
-
|
| 115 |
-
# Save mask image
|
| 116 |
mask_filename = f"mask_image_{i+1}.png"
|
| 117 |
-
|
| 118 |
mask_images.append(mask_filename)
|
| 119 |
|
| 120 |
plt.close() # Close the figure to free up memory
|
|
|
|
| 29 |
transparent_layer = np.zeros((h, w, 4))
|
| 30 |
for index, track in enumerate(tracking_points.value):
|
| 31 |
if trackings_input_label.value[index] == 1:
|
| 32 |
+
cv2.circle(transparent_layer, track, 20, (0, 255, 0, 255), -1)
|
| 33 |
else:
|
| 34 |
cv2.circle(transparent_layer, track, 20, (255, 0, 0, 255), -1)
|
| 35 |
|
|
|
|
| 98 |
|
| 99 |
plt.close() # Close the figure to free up memory
|
| 100 |
|
| 101 |
+
# ---- Separate Mask Image (White Mask on Black Background) ----
|
| 102 |
+
# Create a black image
|
| 103 |
+
mask_image = np.zeros_like(image, dtype=np.uint8)
|
| 104 |
+
|
| 105 |
+
# The mask is a binary array where the masked area is 1, else 0.
|
| 106 |
+
# Convert the mask to a white color in the mask_image
|
| 107 |
+
mask_layer = (mask > 0).astype(np.uint8) * 255
|
| 108 |
+
for c in range(3): # Assuming RGB, repeat mask for all channels
|
| 109 |
+
mask_image[:, :, c] = mask_layer
|
| 110 |
+
|
| 111 |
+
# Save the mask image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
mask_filename = f"mask_image_{i+1}.png"
|
| 113 |
+
Image.fromarray(mask_image).save(mask_filename)
|
| 114 |
mask_images.append(mask_filename)
|
| 115 |
|
| 116 |
plt.close() # Close the figure to free up memory
|