简体   繁体   English

为什么我得到“模块'cv2'没有属性'resize'”

[英]Why am I getting " module 'cv2' has no attribute 'resize'"

I am using the following line in my program我在我的程序中使用以下行

img = cv2.resize(img, dsize=(299, 299), interpolation=cv2.INTER_LINEAR)

It is giving the following error它给出了以下错误

AttributeError: module 'cv2' has no attribute 'resize'

The type of image img is <class 'imageio.core.util.Array'>图像img的类型是<class 'imageio.core.util.Array'>

I checked the official documentation of OpenCV and it contains the attribute resize .我查看了 OpenCV 的官方文档, 它包含属性 resize

Where am I going wrong?我哪里错了?

The issue occurred due to the erroneous installation of OpenCV.该问题是由于 OpenCV 安装错误造成的。

Although the system is behaving as OpenCV was properly installed.尽管系统的行为是正确安装了 OpenCV。 It wasn't installed properly.它没有正确安装。

Uninstalling and installing OpenCV again solved the issue.卸载并安装 OpenCV 再次解决了该问题。

pip uninstall opencv-python

and then接着

pip install opencv-python

Maybe your cv2 import is not correct.也许您的 cv2 导入不正确。 In a Python console, try在 Python 控制台中,尝试

import cv2
help(cv2.resize)

In case it does not show the description of the resize method, the import does not work properly.如果它没有显示 resize 方法的描述,则导入无法正常工作。 Your could also check help(cv2) which gives a long list of all methods and attributes contained in the module.您还可以检查help(cv2) ,它给出了模块中包含的所有方法和属性的长列表。

Are you working within a virtual environment that needs activation first?您是否在需要首先激活的虚拟环境中工作?

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

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