(masks, points, point_label, target_height, target_width)
| 392 | |
| 393 | |
| 394 | def 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 | |
| 418 | def text_prompt(annotations, text, img_path, device, wider=False, threshold=0.9): |
no outgoing calls
no test coverage detected