python3和opencv错误

python3和opencv错误

当我想使用 opencv 时,python3 出现了一些错误。它与 python2 配合良好,但与 python3 配合不好。

import cv2
import numpy as np

img = cv2.imread('test.jpg')
print(img)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()`

我使用的代码。

我收到此错误:

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 "test.py", line 6, in <module>
    cv2.imshow('image',img)
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

因此我尝试使用以下参数重新安装 opencv:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_GTK_2_X=ON  -D CUDA_GENERATION=Kepler ..

但它不起作用,我收到了同样的错误。(sudo make -j8然后sudo make install

此外,我不确定 GTK 是否被 cmake 考虑,因为有以下几行:

GUI: 
--     QT 5.x:                      YES (ver 5.5.1)
--     QT OpenGL support:           YES (Qt5::OpenGL 5.5.1)
--     OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGL.so)
--     VTK support:                 YES (ver 6.2.0)
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8

我怎么解决这个问题?

答案1

你可以尝试

conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv

conda install 后你可能会看到以下错误

Traceback (most recent call last):
    File "./test.py", line 21, in <module>
      import cv2
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory

只需安装 openblas 库即可解决

apt install libopenblas-dev -y

参考

[sdvillal | github]https://github.com/conda-forge/opencv-feedstock/issues/43

相关内容