Resizing the image to a specific width and height with opencv in Python
- 2023年2月08日
- 技術情報
Today, I would like to share a program for resizing the images to a specific width and height with opencv library in Python. Let’s take a look.
Opencv has resize method cv2.resize() to resize the images.
We can resize the images simply as follows.
import cv2
# read the input
img = cv2.imread('input.jpeg')
height, width, channel = img.shape
print(f"Height and width of original image: {height}, {width}")
# resize the image
new_size = (450, 340) # (width, height)
print(f"New height and width: {new_size[1]}, {new_size[0]}")
resize_img = cv2.resize(img, new_size)
cv2.imshow('Original img', img)
cv2.imshow('Resized img', resize_img)
cv2.waitKey(0)
The program above will resize the input image and show original and resized images.
Actually, cv2.resize() has other functionalities. Please study more about this. It is interesting.
This is all for now. Hope you enjoy that.
By Asahi
waithaw at 2023年02月08日 10:00:00