背景
Ubuntu20.04 , 在用opencv进行显示的时候报的错误:
cv2.error: OpenCV(4.9.0) /io/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’
按照报错提示和搜到的教程,需要对OPENCV进行重新编译,但是我没有单独装过opencv,只有一个ROS自带的版本。
解决
进入虚拟环境,看一下opencv-python的版本是4.9,降低版本就好了,这里我换成openv-python=4.1 和 4.6 都可以正常运行。
pip install opencv-python==4.6.0.66 -i https://pypi.tuna.tsinghua.edu.cn/simple
把这个包也装一下
pip install opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn/simple
opencv-python 可以选择的版本如下: