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

Function point_prompt

utils/tools.py:394–415  ·  view source on GitHub ↗
(masks, points, point_label, target_height, target_width)

Source from the content-addressed store, hash-verified

392
393
394def point_prompt(masks, points, point_label, target_height, target_width): # numpy 处理
395 h = masks[0]["segmentation"].shape[0]
396 w = masks[0]["segmentation"].shape[1]
397 if h != target_height or w != target_width:
398 points = [
399 [int(point[0] * w / target_width), int(point[1] * h / target_height)]
400 for point in points
401 ]
402 onemask = np.zeros((h, w))
403 masks = sorted(masks, key=lambda x: x['area'], reverse=True)
404 for i, annotation in enumerate(masks):
405 if type(annotation) == dict:
406 mask = annotation['segmentation']
407 else:
408 mask = annotation
409 for i, point in enumerate(points):
410 if mask[point[1], point[0]] == 1 and point_label[i] == 1:
411 onemask[mask] = 1
412 if mask[point[1], point[0]] == 1 and point_label[i] == 0:
413 onemask[mask] = 0
414 onemask = onemask >= 1
415 return onemask, 0
416
417
418def text_prompt(annotations, text, img_path, device, wider=False, threshold=0.9):

Callers 2

segment_with_pointsFunction · 0.90
promptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected