Python OpenCV image scaling: using the cv2.resize() method

Image scaling is one of the commonly used operations in computer vision and image processing. OpenCV is a powerful computer vision library that provides many image processing functions. Image scaling with OpenCV in Python is very simple and can be achieved using the cv2.resize() method.

The cv2.resize() method resizes the image according to the specified dimensions. It can reduce the size of the image and also enlarge the image. This method can accept the following parameters:

  • src: The input image to be scaled.
  • dsize: The target size after scaling, which can be a tuple (width, height) or an integer.
  • fx: Scale ratio in the horizontal direction.
  • fy: Scale ratio in the vertical direction.
  • interpolation: Interpolation method used to determine how to process the value of new pixels. Commonly used interpolation methods include cv2.INTER_LINEAR, cv2.INTER_NEAREST, cv2.INTER_CUBIC, etc.

Here is a sample code that demonstrates how to resize an image using the cv2.resize() method:

import cv2

# 读取输入图像
image = cv2.imread('input.jpg')

# 指定缩放后的目标尺寸
target_size 

Guess you like

Origin blog.csdn.net/UtiExamples/article/details/133128463