[英]Python 3 Opencv set up problem: "cannot find reference 'VideoCapture' in __init__.py" on Pycharm IDE
I am trying to install OpenCv and run some code on PyCharm on Mac.我正在尝试安装 OpenCv 并在 Mac 上的 PyCharm 上运行一些代码。
I have installed the opencv package as well as numpy but when I run the code this error shows up on Pycharm IDE: "cannot find reference 'VideoCapture' in __init__.py"
我已经安装了 opencv package 以及 numpy,但是当我运行代码时,此错误显示在 Pycharm IDE 上: "cannot find reference 'VideoCapture' in __init__.py"
In fact, every time I write example_variable = cv2.
其实每次写example_variable = cv2.
, PyCharm is not giving me any option to autocomplete with a function attached to cv2. , PyCharm 没有给我任何选项来自动完成附加到 cv2 的 function。 Why is this happening?为什么会这样?
Here's the code I am trying to run.这是我要运行的代码。 I tried also running other codes but the same error displays:我也尝试运行其他代码,但显示相同的错误:
import cv2
import numpy as np
cap = cv2.VideoCapture()
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & OxFF == ord('q'):
break
cap.release
cv2.destroyAllWindows()
Any tips on how to run this code smoothly?有关如何顺利运行此代码的任何提示? The end goal is to have my front webcam capture live video and react to it.最终目标是让我的前置网络摄像头捕捉实时视频并对其做出反应。
Try one of this solutions:尝试以下解决方案之一:
OR:或者:
After all that, you can also delete the .idea folder in your root directory and restart the IDE.毕竟,您还可以删除根目录中的 .idea 文件夹并重新启动 IDE。
而不是import cv2
使用from cv2 import cv2
I agree with "from cv2 import cv2"我同意“从 cv2 导入 cv2”
there have an another way to solve problems:还有另一种解决问题的方法:
** Do Not Use Pip Install ** ** 不要使用 Pip 安装 **
I try to use download opencv_python-4.5.5.62-cp36-abi3-win_amd64.whl file and then manual double click to install我尝试使用下载 opencv_python-4.5.5.62-cp36-abi3-win_amd64.whl 文件然后手动双击安装
wait a minute, Pycharm IDE successfully Show code completion.稍等一下,Pycharm IDE 成功显示代码完成。
by the way,can your code run?顺便问一下,你的代码可以运行吗?
if code can run, above will help you a bit.如果代码可以运行,上面会帮助你一点。
and your path(project python) should be Englisgh ;并且您的路径(项目 python)应该是 Englisgh ; not be Chinese or other language.不是中文或其他语言。
This worked for这适用于
pip install --force-reinstall --no-cache -U opencv-python==4.5.5.62 pip 安装 --force-reinstall --no-cache -U opencv-python==4.5.5.62
只需输入 from cv2 import cv2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.