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?
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...
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With