简体   繁体   English

cv2.resize 中的 None 是什么意思?

[英]What does None in cv2.resize mean?

I came across the following snippet used to resize an image:我遇到了以下用于调整图像大小的代码段:

img = cv2.resize(img, None, fx = 1/3, fy = 1/3)

What is the call actually doing?电话实际上在做什么? Why is the output size parameter set to None ?为什么输出大小参数设置为None When I tried to run this snippet with OpenCV 3.4.3 , it gives an error but works fine with OpenCV 3.4.2 .当我尝试使用OpenCV 3.4.3运行此代码段时,它给出了一个错误,但在OpenCV 3.4.2运行良好。

I want to emulate this behavior in OpenCV 3.4.3 .我想在OpenCV 3.4.3模拟这种行为。 What is it doing and how I could do it?它在做什么,我该怎么做?

OpenCV function resize has 2 different modes for resizing the image. OpenCV 函数resize有 2 种不同的调整图像大小的模式。

  1. A fixed output size can be specified in the 2nd parameter.可以在第二个参数中指定固定的输出大小。
  2. Scaling factor for each dimension can be specified using the fx and fy parameters which are used for calculating the output size.可以使用用于计算输出大小的fxfy参数指定每个维度的缩放因子。

If both methods are used simultaneously, then fx and fy parameters are ignored.如果同时使用这两种方法,则忽略fxfy参数。 The output size parameter is mandatory for both cases.对于这两种情况,输出大小参数都是必需的。 It means that if we want to use the scaling method, we have to pass None in place of the output size parameter.这意味着如果我们想使用缩放方法,我们必须传递None来代替输出大小参数。 None indicates that we do not want to use this parameter. None表示我们不想使用这个参数。

Example Usage:示例用法:

Fixed output size:固定输出尺寸:

img = cv2.resize( img, (640, 480) )

Dynamic output size:动态输出尺寸:

img = cv2.resize(img, None, fx = 1.0/3.0, fy = 1.0/3.0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM