images.py 文件源码

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

项目:car-detection 作者: mmetcalfe 项目源码 文件源码
def resize_sample(sample, shape=None, use_interp=True, scale=None):
    if (shape and scale) or (not shape and not scale):
        raise ValueError('Must specify exactly one of shape or scale, but got shape=\'{}\', scale=\'{}\''.format(shape, scale))

    # Use INTER_AREA for shrinking and INTER_LINEAR for enlarging:
    interp = cv2.INTER_NEAREST
    if use_interp:
        target_is_smaller = (shape and shape[1] < sample.shape[1]) or (scale and scale < 1) # targetWidth < sampleWidth
        interp = cv2.INTER_AREA if target_is_smaller else cv2.INTER_LINEAR

    if shape:
        resized = cv2.resize(sample, (shape[1], shape[0]), interpolation=interp)
    else:
        resized = cv2.resize(sample, None, fx=scale, fy=scale, interpolation=interp)

    return resized
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号