【精华】OpenCV常见报错信息及解决方法汇总

1 报错信息:安装opencv-python报超时
>>> pip install opencv-python
Collecting opencv-python
  Downloading opencv_python-4.5.5.64-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (60.5 MB)
     || 307 kB 8.7 kB/s eta 1:55:00ERROR: Exception:
Traceback (most recent call last):
  File "/home/leezhao/anaconda3/lib/python3.9/site-packages/pip/_vendor/urllib3/response.py", line 438, in _error_catcher
    yield
  File "/home/leezhao/anaconda3/lib/python3.9/site-packages/pip/_vendor/urllib3/response.py", line 519, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "/home/leezhao/anaconda3/lib/python3.9/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "/home/leezhao/anaconda3/lib/python3.9/http/client.py", line 463, in read
    n = self.readinto(b)
  File "/home/leezhao/anaconda3/lib/python3.9/http/client.py", line 507, in readinto
    n = self.fp.readinto(b)
  File "/home/leezhao/anaconda3/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "/home/leezhao/anaconda3/lib/python3.9/ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "/home/leezhao/anaconda3/lib/python3.9/ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
解决方法

使用豆瓣源下载opencv-python

pip install opencv-python -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
或者
pip install opencv-python -i https://pypi.doubanio.com/simple
2 报错信息:‘cvWaitKey’
cv2.error: OpenCV(4.5.5) /io/opencv/modules/highgui/src/window.cpp:1334: 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 'cvWaitKey'
或
cv2.error: OpenCV(4.5.5) /io/opencv/modules/highgui/src/window.cpp:651: 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'
原因分析

opencv-python需要配套扩展库opencv-contrib-python使用

解决办法
pip install --upgrade pip
pip install opencv-contrib-python
3 报错信息:‘_registerMatType’
ImportError: cannot import name '_registerMatType' from 'cv2.cv2'
原因分析

opencv-python-headless版本过高

解决方法
pip uninstall opencv-python-headless
pip install "opencv-python-headless<4.3"
4 报错信息:protobuf
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
原因分析

protobuf 版本过高

解决方法
pip uninstall protobuf
pip install protobuf==3.20
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值