Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python cv2 resize keep aspect ratio

def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA):
    # initialize the dimensions of the image to be resized and
    # grab the image size
    dim = None
    (h, w) = image.shape[:2]

    # if both the width and height are None, then return the
    # original image
    if width is None and height is None:
        return image

    # check to see if the width is None
    if width is None:
        # calculate the ratio of the height and construct the
        # dimensions
        r = height / float(h)
        dim = (int(w * r), height)

    # otherwise, the height is None
    else:
        # calculate the ratio of the width and construct the
        # dimensions
        r = width / float(w)
        dim = (width, int(h * r))

    # resize the image
    resized = cv2.resize(image, dim, interpolation = inter)

    # return the resized image
    return resized
Comment

PREVIOUS NEXT
Code Example
Python :: print on two digit python format 
Python :: meme command discord.py 
Python :: background image in python 
Python :: pandas columns add prefix 
Python :: python how to get html code from url 
Python :: python pandas change column values to all caps 
Python :: how to remove the very last character of a text file in python 
Python :: sum of a column in pandas 
Python :: python detect keypress 
Python :: mape python 
Python :: length ofarray in ptyon 
Python :: asyncio wirte to text python 
Python :: how to print the text of varying length in python 
Python :: how to increase and decrease volume of speakers using python 
Python :: flask download a file 
Python :: pandas show complete string 
Python :: to_dataframe pandas 
Python :: convert string representation of dict to dict python 
Python :: python afficher hello world 
Python :: how to use an indefinite number of args in python 
Python :: how to calculate average in list python by using whil loop 
Python :: python dump object print 
Python :: in pandas series hot to count the numer of appearences 
Python :: how to return only fractional part in python 
Python :: array must not contain infs or NaNs 
Python :: turn of axis 
Python :: django rest framework delete file 
Python :: ubuntu download file command line 
Python :: flatten an irregular list of lists 
Python :: numpy series reset index 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =