Python image scaling: detailed resize() function

Python image scaling: detailed resize() function

In Python, it is often necessary to zoom in on pictures. To achieve this function, you can use the resize() function provided by the OpenCV library. This article will introduce the basic usage of the resize() function and provide some specific code examples.

Basic usage of the resize() function

The complete syntax of the resize() function is as follows:

cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])

Among them, the meaning of the parameters is as follows:

  • src: the original image.
  • dsize: target image size.
  • dst: target image, you can not pass in, the function will create one automatically.
  • fx: scaling along the horizontal direction.
  • fy: the zoom ratio along the vertical direction.
  • interpolation: interpolation method, optional values ​​include cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_CUBIC, cv2.INTER_LANCZOS4, etc.

Here's a simple example where we scale a 480x640 image to 960x1280:

import cv2

img = cv2.imread('image.jpg'

Guess you like

Origin blog.csdn.net/update7/article/details/129807997