Q:

Opencv Python resize with one constant

I want to resize my image with given one edge's new length by using cv2.resize() method.
For example my image has dimension 300x400, and I want to increase my height from 400 to 500 but I should write only one edge's new size(just 500), the other edge should automatically be increased. What is sequence?

A:

I know you are asking for cv2.resize only, but you could use the imutils library which does some of the ratio code for you. 
import imutils
resized = imutils.resize(img, width=newwidth)

Inside imutils:
dim = None
(h, w) = image.shape[:2]

# 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)

