openCV系列文章目录
文章目录
- openCV系列文章目录
- 前言
- 一、错误原因
- 二、解决方法
- 1.在vscode:Python:Select Interpreter
- 2.依然报错:cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
- 3.再次报错:WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000028558508F40>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/f0/cc/3b7408b8ecf7c1d20ad480c3eaed7619857bf1054b690226e906fdf14258/ffmpeg-1.4.tar.gz
- 4.在vscode终端重装opencv-python
- 5.代码
- 6.运行
前言
在vscode中使用opencv-python报错:
一、错误原因
1.首先
numpy matplotlib opencv_python这些我已经在本机配置安装
pip install numpy matplotlib opencv_python
二、解决方法
1.在vscode:Python:Select Interpreter
当python环境不止一个时,vscode可以选择指定的python解释器,具体为:
vscode设置中打开Command Palette,ctrl+shift+p
输入Python:Select Interpreter
根据自己机器的python.exe 选择
这样vscode下能够识别cv2
2.依然报错:cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function ‘cvShowImage’
解决方法:在vscode终端输入 :pip install ffmpeg
3.再次报错:WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000028558508F40>, ‘Connection to files.pythonhosted.org timed out. (connect timeout=15)’)’: /packages/f0/cc/3b7408b8ecf7c1d20ad480c3eaed7619857bf1054b690226e906fdf14258/ffmpeg-1.4.tar.gz
解决:卸载opencv-python
4.在vscode终端重装opencv-python
pip install opencv-python
5.代码
import cv2
img = cv2.imread('E:/openCVExercise/pythonOpenCV/1.jpg')
cv2.imshow('img', img)
cv2.waitKey(0)