def get_search_region(bbox, frame, ratio):
"""
Calculates coordinates of ratio*width/height of axis-aligned bbox, centred
on the original bbox, constrained by the original size of the image.
Arguments:
bbox = axis-aligned bbox of the form [x0, y0, width, height]
frame = MxNxD Image to constrain bbox by
ratio = ratio at which to change bbox dimensions by
Output:
x0, y0, x1, y1 = Coordinates of expanded axis-aligned bbox
"""
x0, y0, w, h = bbox
ih, iw = frame.shape[:2]
ww, hh = ratio*w, ratio*h
# expand bbox by ratio
x1 = np.min([iw-1, x0 + w/2 + ww/2])
y1 = np.min([ih-1, y0 + h/2 + hh/2])
x0 = np.max([0, x0 + w/2 - ww/2])
y0 = np.max([0, y0 + h/2 - hh/2])
x0, y0, x1, y1 = np.rint(np.array([x0, y0, x1, y1])).astype('int')
return x0, y0, x1, y1
评论列表
文章目录