简体   繁体   English

Python/OpenCV:使用 cv2.resize() 我得到一个错误

[英]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.

相关问题 OpenCV 中的 cv2.resize() 是否有用于缩小图像的替代方法? - Is there an alternative to cv2.resize() in OpenCV for downscaling images? cv2.Resize() 在 OpenCV 编译后不起作用 - cv2.Resize() not working after OpenCV compilation 使用cv2.resize后获取旋转矩形的大小和位置 - Get size and position of rotated rectangle after using cv2.resize 如何替换 python 中的 cv2.resize() - How to replace cv2.resize() in python cv2.resize() - 错误 - OpenCV(4.2.0) - 错误:(-215:Assertion failed) - 循环图像 - cv2.resize() - error - OpenCV(4.2.0) - error: (-215:Assertion failed) - loop over images 尝试使用 cv2.resize 调整大小时出现错误消息 - Error message when trying to resize with cv2.resize small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' - small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' cv2.resize()错误:使用不同的名称保存相同的图片 - cv2.resize() error: saves the same picture with different names cv2.resize与Python:插值方法到底是什么? - cv2.resize with Python : what exactly does the interpolation methods? 为什么 cv2.resize 转置请求的尺寸? - Why is cv2.resize transposing the requested dimensions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM