def scale_min ( im , targ , interpolation = cv2 . INTER_AREA ) : r , c ,  * _ = im . shape ratio = targ / min ( r , c ) sz = ( scale_to ( c , ratio , targ ) , scale_to ( r , ratio , targ ) ) return cv2 . resize ( im , sz , interpolation = interpolation )
opencv resize keep ratio python
Scale the image so that the smallest axis is of size targ .
def scale_min(im, targ, interpolation=cv2.INTER_AREA):
    """ Scale the image so that the smallest axis is of size targ.

    Arguments:
        im (array): image
        targ (int): target size
    """
    r,c,*_ = im.shape
    ratio = targ/min(r,c)
    sz = (scale_to(c, ratio, targ), scale_to(r, ratio, targ))
    return cv2.resize(im, sz, interpolation=interpolation)