zinon zinon - 4 months ago 32
Python Question

Python/OpenCV: Using cv2.resize() I get an error

I'm using python 2.7 and opencv.

I'm trying to use:

cv2.resize(src, dst, Size(), 0.5, 0.5, interpolation=cv2.INTER_LINEAR);

taken from here. But when I run this code I get
NameError: global name 'Size' is not defined.

Can you help me please?


You are probably looking at the C++ api of resize method.

The python API looks something like this:

dst = cv2.resize(src, dsize)


src - Original image
dsize - a tuple defining the final size of the image.

If you want to pass additional parameters then you may use the named parameters of the API as:

dst = cv2.resize(src, dsize, fx = 0.5, fy=0.5, interpolation = cv2.INTER_LINEAR)

Since dsize is required param but if you still want the resize method to calculate the dsize for you then you may pass the param as None.

dst = cv2.resize(src, None, fx = 0.5, fy=0.5)