Update demo/sam_inference.py
Browse files- demo/sam_inference.py +19 -0
demo/sam_inference.py
CHANGED
@@ -53,6 +53,25 @@ class SAM_Inference:
|
|
53 |
|
54 |
return process_mask_to_show(mask), res, mask
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
def run_inference(self, input_x, selected_points):
|
57 |
if len(selected_points) == 0:
|
58 |
return []
|
|
|
53 |
|
54 |
return process_mask_to_show(mask), res, mask
|
55 |
|
56 |
+
def gen_box_point(self, inp):
|
57 |
+
if inp is None:
|
58 |
+
raise gr.Error("Please upload an image first!")
|
59 |
+
image = inp['image']
|
60 |
+
if len(inp['boxes']) == 0:
|
61 |
+
raise gr.Error("Please clear the raw boxes and draw a box first!")
|
62 |
+
boxes = inp['boxes'][-1]
|
63 |
+
|
64 |
+
input_box = np.array([boxes[0], boxes[1], boxes[2], boxes[3]]).astype(int)
|
65 |
+
mask = np.zeros_like(image[:,:,0])
|
66 |
+
|
67 |
+
mask[input_box[1]:input_box[3], input_box[0]:input_box[2]] = 1 # generate the mask based on bbox points
|
68 |
+
|
69 |
+
colored_mask = mask_foreground(mask)
|
70 |
+
res = img_add_masks(image, colored_mask, mask)
|
71 |
+
|
72 |
+
return process_mask_to_show(mask), res, mask
|
73 |
+
|
74 |
+
|
75 |
def run_inference(self, input_x, selected_points):
|
76 |
if len(selected_points) == 0:
|
77 |
return []
|