[英]Python/OpenCV: Using cv2.resize() I get an error
I'm using python 2.7 and opencv.我正在使用 python 2.7 和 opencv。
I'm trying to use:我正在尝试使用:
cv2.resize(src, dst, Size(), 0.5, 0.5, interpolation=cv2.INTER_LINEAR);
taken from here .取自这里。 But when I run this code I get
NameError: global name 'Size' is not defined.
但是当我运行这段代码时,我得到
NameError: global name 'Size' is not defined.
Can you help me please?你能帮我吗?
You are probably looking at the C++ api of resize
method.您可能正在查看
resize
方法的 C++ api。
The python API looks something like this: python API 看起来像这样:
dst = cv2.resize(src, dsize)
where在哪里
src - Original image
dsize - a tuple defining the final size of the image.
If you want to pass additional parameters then you may use the named parameters of the API as:如果你想传递额外的参数,那么你可以使用 API 的命名参数:
dst = cv2.resize(src, dsize, fx = 0.5, fy=0.5, interpolation = cv2.INTER_LINEAR)
Since dsize is required param but if you still want the resize
method to calculate the dsize
for you then you may pass the param as None
.由于 dsize 是必需的参数,但如果您仍然希望
resize
方法为您计算dsize
,那么您可以将参数作为None
传递。
dst = cv2.resize(src, None, fx = 0.5, fy=0.5)
The previous answer was OK, but I wanted to reuse storage--to resize image
to fit into existing storage resized
(both 3-dimensional uint8
numpy arrays), I needed to use以前的答案是好的,但我想重用存储 - 调整
image
大小以适应resized
现有存储(都是 3 维uint8
numpy 数组),我需要使用
ret = cv2.resize(image, dsize=resized.shape[:2][::-1], dst=resized)
Note that the dsize argument is backwards--it's not (rows, columns), but (width, height), hence the [::-1]
.请注意, dsize 参数是向后的——它不是 (rows, columns),而是 (width, height),因此是
[::-1]
。
I return ret
only to confirm that indeed (ret == resized).all()
.我返回
ret
只是为了确认确实(ret == resized).all()
。
# lets doubled the size of our image/ increasing the size...
img_double_scaled = cv2.resize(img, None, fx = 1.5, fy = 1.5, interpolation = cv2.INTER_CUBIC)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.