Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imresize error using OpenCV 2.4.10 and Python 2.7.10

I'm trying to resize an image with OpenCV 2.4.10 and Python 2.7.10.

This works:

resized_patch = cv2.resize(patch, (3, 50, 50))

However, I'm interested in using INTER_AREA interpolation. Following the documentation for Python, I tried:

dst = numpy.zeros((3, 50, 50))
resized_patch = cv2.resize(patch, (3, 50, 50), dst=dst, fx=0, fy=0, interpolation=cv2.INTER_AREA)

However, the error I'm getting from the cv2.resize line is:

TypeError: 'function takes exactly 2 arguments (3 given)'

Any clues?

like image 703
unicorn_poet Avatar asked Jul 22 '15 13:07

unicorn_poet


People also ask

What is image resizing in OpenCV?

Image Resizing using OpenCV | Python. Image resizing refers to scaling of images. Scaling comes handy in many image processing as well as machine learning applications. It helps in reducing the number of pixels from an image and that has several advantages e.g. It can reduce the time of training of a neural network as more is the number...

How to resize images in CV2 in Python?

Resize the image using cv2.resize () function. Place the output file inside the output folder using cv2.imwrite () function. All the images inside the Images folder will be resized and will be saved in an output folder. Open the terminal in the folder where this Python Script is saved and type the below command.

How to resize an image using interpolation in OpenCV?

OpenCV provides us several interpolation methods for resizing an image. cv2.INTER_AREA: This is used when we need need to shrink an image. cv2.INTER_CUBIC: This is slow but more efficient. cv2.INTER_LINEAR: This is primarily used when zooming is required. This is the default interpolation technique in OenCV.

How is OpenCV different from other image-processing libraries?

One important thing to note here is that OpenCV outputs the shape of an image in format, whereas some other image-processing libraries give in the form of width, height. There’s a logical take to this. When images are read using OpenCV, they are represented as NumPy arrays.


Video Answer


1 Answers

You need to use a 2D size for dst.size() not 3D :

resized_patch = cv2.resize(patch, (3, 50, 50), dst=dst, fx=0, fy=0, interpolation=cv2.INTER_AREA)
                                      ^^^ #here 
like image 131
Mazdak Avatar answered Oct 25 '22 21:10

Mazdak