Converts an axis-aligned bounding box to points. Args: mode: The mode specifying how to interpret the bounding box. bbox: Bounding boxes of the shape (N, C) for N boxes. C is [x1, y1, x2, y2] for 2D or [x1, y1, z1, x2, y2, z2] for 3D for each box. Return shape w
(bbox, mode)
| 656 | |
| 657 | |
| 658 | def convert_box_to_points(bbox, mode): |
| 659 | """ |
| 660 | Converts an axis-aligned bounding box to points. |
| 661 | |
| 662 | Args: |
| 663 | mode: The mode specifying how to interpret the bounding box. |
| 664 | bbox: Bounding boxes of the shape (N, C) for N boxes. C is [x1, y1, x2, y2] for 2D or [x1, y1, z1, x2, y2, z2] |
| 665 | for 3D for each box. Return shape will be (N, 4, 2) for 2D or (N, 8, 3) for 3D. |
| 666 | |
| 667 | Returns: |
| 668 | sequence of points representing the corners of the bounding box. |
| 669 | """ |
| 670 | |
| 671 | mode = get_boxmode(mode) |
| 672 | |
| 673 | points_list = [] |
| 674 | for _num in range(bbox.shape[0]): |
| 675 | corners = mode.boxes_to_corners(bbox[_num : _num + 1]) |
| 676 | if len(corners) == 4: |
| 677 | points_list.append( |
| 678 | concatenate( |
| 679 | [ |
| 680 | concatenate([corners[0], corners[1]], axis=1), |
| 681 | concatenate([corners[2], corners[1]], axis=1), |
| 682 | concatenate([corners[2], corners[3]], axis=1), |
| 683 | concatenate([corners[0], corners[3]], axis=1), |
| 684 | ], |
| 685 | axis=0, |
| 686 | ) |
| 687 | ) |
| 688 | else: |
| 689 | points_list.append( |
| 690 | concatenate( |
| 691 | [ |
| 692 | concatenate([corners[0], corners[1], corners[2]], axis=1), |
| 693 | concatenate([corners[3], corners[1], corners[2]], axis=1), |
| 694 | concatenate([corners[3], corners[4], corners[2]], axis=1), |
| 695 | concatenate([corners[0], corners[4], corners[2]], axis=1), |
| 696 | concatenate([corners[0], corners[1], corners[5]], axis=1), |
| 697 | concatenate([corners[3], corners[1], corners[5]], axis=1), |
| 698 | concatenate([corners[3], corners[4], corners[5]], axis=1), |
| 699 | concatenate([corners[0], corners[4], corners[5]], axis=1), |
| 700 | ], |
| 701 | axis=0, |
| 702 | ) |
| 703 | ) |
| 704 | |
| 705 | return stack(points_list, dim=0) |
| 706 | |
| 707 | |
| 708 | def convert_points_to_box(points): |
no test coverage detected
searching dependent graphs…