create_test_cropped_image.py 文件源码

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

项目:kaggle-right-whale 作者: felixlaumon 项目源码 文件源码
def get_cropped_test_img(fname, bbox_pred, pad=None, as_grey=False, return_bbox=False):
    img = imread(fname, as_grey=as_grey)
    h = img.shape[0]
    w = img.shape[1]
    bbox_pred = bbox_pred * [w, h, w, h]
    bbox_pred = np.round(bbox_pred).astype(int)
    l = min(max(bbox_pred[0], 0), w)
    t = min(max(bbox_pred[1], 0), h)
    r = min(max(l + bbox_pred[2], 0), w)
    b = min(max(t + bbox_pred[3], 0), h)

    if pad is not None:
        l, t, r, b = add_padding_to_bbox(
            l, t, (r - l), (b - t), pad / 100.0,
            img.shape[1], img.shape[0],
            format='ltrb'
        )
    cropped_img = img[t:b, l:r]

    if return_bbox:
        return cropped_img, bbox_pred
    else:
        return cropped_img
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号