MCPcopy Index your code
hub / github.com/CASIA-LMC-Lab/FastSAM / segment_with_points

Function segment_with_points

app_gradio.py:118–164  ·  view source on GitHub ↗
(
    input,
    input_size=1024, 
    iou_threshold=0.7,
    conf_threshold=0.25,
    better_quality=False,
    withContours=True,
    use_retina=True,
    mask_random_color=True,
)

Source from the content-addressed store, hash-verified

116
117
118def segment_with_points(
119 input,
120 input_size=1024,
121 iou_threshold=0.7,
122 conf_threshold=0.25,
123 better_quality=False,
124 withContours=True,
125 use_retina=True,
126 mask_random_color=True,
127):
128 global global_points
129 global global_point_label
130
131 input_size = int(input_size) # 确保 imgsz 是整数
132 # Thanks for the suggestion by hysts in HuggingFace.
133 w, h = input.size
134 scale = input_size / max(w, h)
135 new_w = int(w * scale)
136 new_h = int(h * scale)
137 input = input.resize((new_w, new_h))
138
139 scaled_points = [[int(x * scale) for x in point] for point in global_points]
140
141 results = model(input,
142 device=device,
143 retina_masks=True,
144 iou=iou_threshold,
145 conf=conf_threshold,
146 imgsz=input_size,)
147
148 results = format_results(results[0], 0)
149 annotations, _ = point_prompt(results, scaled_points, global_point_label, new_h, new_w)
150 annotations = np.array([annotations])
151
152 fig = fast_process(annotations=annotations,
153 image=input,
154 device=device,
155 scale=(1024 // input_size),
156 better_quality=better_quality,
157 mask_random_color=mask_random_color,
158 bbox=None,
159 use_retina=use_retina,
160 withContours=withContours,)
161
162 global_points = []
163 global_point_label = []
164 return fig, None
165
166
167def get_points_with_draw(image, label, evt: gr.SelectData):

Callers

nothing calls this directly

Calls 3

format_resultsFunction · 0.90
point_promptFunction · 0.90
fast_processFunction · 0.90

Tested by

no test coverage detected