util.py 文件源码

python
阅读 39 收藏 0 点赞 0 评论 0

项目:initialisation-problem 作者: georgedeath 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号