OpenCV报错: If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then...

在Ubuntu20.04环境下使用opencv遇到显示错误,解决方案是在ROS自带opencv的基础上,通过创建虚拟环境并降低opencv-python至4.6.0.66版本来解决问题。还需安装opencv-contrib-python。
摘要由CSDN通过智能技术生成

背景

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 可以选择的版本如下:
在这里插入图片描述

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Goafan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值