首先导入 cv 库是没问题的:
能够看到 opencv 的版本信息,但是在我使用的时候报错:
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /opt/conda/conda-bld/opencv_1491943970124/work/opencv-3.1.0/modules/highgui/src/window.cpp, line 527
Traceback (most recent call last):
File "test.py", line 3, in <module>
cv2.namedWindow("Image")
cv2.error: /opt/conda/conda-bld/opencv_1491943970124/work/opencv-3.1.0/modules/highgui/src/window.cpp:527: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow
原因:opencv 功能不完整
坑:不要按照错误提示说的什么重新 cmake
解决方法:
重装 opencv:
conda install --channel https://conda.anaconda.org/menpo opencv3
这样安装的是 opencv3.1 版本,如果需要更高版本可以从官网直接下载需要的版本,然后 cd 到目录下,用 pip install 进行安装。
官网:https://pypi.org/project/opencv-python/#files
或者这样也可以:
pip install opencv-python -i https://pypi.douban.com/simple
以上解决办法参考良心帖:https://blog.csdn.net/leviopku/article/details/79247236
按照这个方法重装之后真的好了!!!Levi 兵长护体