You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

23 lines
730 B

import numpy as np
# from icecream import ic
def get_surrounding_bboxes(bboxes: np.ndarray, point: np.ndarray):
is_surrounding = np.all(bboxes[:, :2] - point < 0, axis=1) * \
np.all(bboxes[:, :2] + bboxes[:, 2:] - point > 0, axis=1)
return bboxes[is_surrounding]
def get_bbox_by_point(bboxes: np.ndarray, point: np.ndarray):
surrounding_bboxes = bboxes
if len(surrounding_bboxes) < 1:
bbox = None
elif len(surrounding_bboxes) == 1:
bbox = surrounding_bboxes[0]
else:
centers = surrounding_bboxes[:, :2] + surrounding_bboxes[:, 2:]/2
dist = np.linalg.norm(centers - point, axis=1)
bbox = surrounding_bboxes[np.argmin(dist)]
return bbox