我的代码是
import numpy as np
import cv2 as cv
img = cv.imread('img.jpg',0)
cv.imshow('image',img)
cv.waitKey(0)
cv.destroyAllWindows()
错误是
Traceback (most recent call last):
File "opencv.py", line 5, in <module>
cv.imshow('image',img)
cv2.error: OpenCV(3.4.2) /tmp/build/80754af9/opencv-suite_1535558553474 /work/modules/highgui/src/window.cpp:632: error: (-2: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 function 'cvShowImage'
答案1
安装两个缺少的依赖包。在所有当前支持的 Ubuntu 版本中打开终端并输入:
sudo apt update
sudo apt install libgtk2.0-dev pkg-config python3-opencv
安装这些软件包后,问题中的 Python 代码在 Ubuntu 18.04 中成功运行。我安装的所有软件包都来自默认的 Ubuntu 18.04 存储库。
- python3-版本 3.6
- python3-numpy
- python3-opencv
- libgtk2.0-dev
- pkg 配置