我刚刚从这里安装了 opencv 3.1关联。构建 opencv 时没有问题或错误。因此,我使用 检查了我的版本cv2.__version__
,它运行良好,但当我使用 测试它时
temp = cv2.imread('test.png')
cv2.imshow('img',temp)
我收到此错误,我不明白问题出在哪里?构建时没有出现任何问题,我仔细按照说明进行操作。以下是错误:
>>> cv2.imshow('img',temp)
OpenCV Error: 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 cvShowImage, file /io/opencv/modules/highgui/src/window.cpp, line 583
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cv2.error: /io/opencv/modules/highgui/src/window.cpp:583: error: (-2) 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
libgtk2.0
首先,使用以下命令检查是否已安装:
sudo aptitude search libgtk2.0-dev
如果依赖关系被破坏,只需使用以下命令安装它的新副本:
sudo aptitude install libgtk2.0-dev
答案2
您可能需要禁用 QT 并启用 GTK_2_X
cmake -DWITH_IPP=ON -DWITH_QT=OFF -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DENABLE_PRECOMPILED_HEADERS=OFF WITH_GTK_2_X=ON -DCMAKE_INSTALL_PREFIX=/usr ..
加
sudo apt install libgtk2.0-dev pkg-config
答案3
不用担心,伙计,我也遇到了同样的问题,这就是我摆脱这个错误的方法,看看你是否通过 pip 或 pip3 或 apt-get 安装了 opencv,首先你必须卸载它
sudo pip3 uninstall (what you wrote while installing)
or sudo pip uninstall (what you wrote while installing)
or sudo apt-get remove (what you wrote while installing)
然后从 github 的源代码构建 opencv 包。
git clone https://github.com/opencv/opencv.git
cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
这样就能解决问题了。祝一切顺利。