boxes_filter.py 845 B

123456789101112131415161718192021222324252627
  1. import numpy as np
  2. def filter_small_boxes(boxes, min_width, min_height):
  3. """Remove all boxes with side smaller than min size.
  4. Args:
  5. boxes: a numpy array with shape [N, 4] holding N boxes.
  6. min_width (float): minimum width
  7. min_height (float): minimum height
  8. Returns:
  9. keep: indices of the boxes that have width larger than
  10. min_width and height larger than min_height.
  11. References:
  12. `_filter_boxes` in py-faster-rcnn
  13. `prune_small_boxes` in TensorFlow object detection API.
  14. `structures.Boxes.nonempty` in detectron2
  15. `ops.boxes.remove_small_boxes` in torchvision
  16. """
  17. widths = boxes[:, 2] - boxes[:, 0]
  18. heights = boxes[:, 3] - boxes[:, 1]
  19. keep = (widths >= min_width)
  20. keep &= (heights >= min_height)
  21. return np.nonzero(keep)[0]