简体   繁体   中英

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'>

I checked the official documentation of OpenCV and it contains the attribute resize .

Where am I going wrong?

The issue occurred due to the erroneous installation of OpenCV.

Although the system is behaving as OpenCV was properly installed. It wasn't installed properly.

Uninstalling and installing OpenCV again solved the issue.

pip uninstall opencv-python

and then

pip install opencv-python

Maybe your cv2 import is not correct. In a Python console, try

import cv2
help(cv2.resize)

In case it does not show the description of the resize method, the import does not work properly. Your could also check help(cv2) which gives a long list of all methods and attributes contained in the module.

Are you working within a virtual environment that needs activation first?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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