def resize ( im , short , max_size ) : im_shape = im . shape im_size_min = np . min ( im_shape [ 0 : 2 ] ) im_size_max = np . max ( im_shape [ 0 : 2 ] ) im_scale = float ( short ) / float ( im_size_min ) # prevent bigger axis from being more than max_size: if np . round ( im_scale * im_size_max ) > max_size : im_scale = float ( max_size ) / float ( im_size_max ) im = cv2 . resize ( im , None , None , fx = im_scale , fy = im_scale , interpolation = cv2 . INTER_LINEAR ) return im , im_scale
cv2 resize not working python
only resize input image to target size and return scale : param im : BGR image input by opencv : param short : one dimensional size ( the short side ) : param max_size : one dimensional max size ( the long side ) : return : resized image ( NDArray ) and scale ( float )
def resize(im, short, max_size):
    """
    only resize input image to target size and return scale
    :param im: BGR image input by opencv
    :param short: one dimensional size (the short side)
    :param max_size: one dimensional max size (the long side)
    :return: resized image (NDArray) and scale (float)
    """
    im_shape = im.shape
    im_size_min = np.min(im_shape[0:2])
    im_size_max = np.max(im_shape[0:2])
    im_scale = float(short) / float(im_size_min)
    # prevent bigger axis from being more than max_size:
    if np.round(im_scale * im_size_max) > max_size:
        im_scale = float(max_size) / float(im_size_max)
    im = cv2.resize(im, None, None, fx=im_scale, fy=im_scale, interpolation=cv2.INTER_LINEAR)
    return im, im_scale