错误描述:
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 cvNamedWindow, file /io/opencv/modules/highgui/src/window.cpp, line 565
Traceback (most recent call last):
File "video_tools/demo.py", line 103, in <module>
cv2.namedWindow('ret',0)
cv2.error: /io/opencv/modules/highgui/src/window.cpp:565: 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 cvNamedWindow
分析:
在Ubuntu16.04下安装OpenCV3.2之前,确实已经提前安装了各种依赖包,特别是libgtk2.0-dev and pkg-config已经确认安装,通过在python下使用cv2.getBuildInformation()
查看:
GUI:
QT: NO
GTK+: NO
GThread : YES (ver 2.12.3)
GtkGlExt: NO
OpenGL support: NO
VTK support: NO
Media I/O:
ZLib: zlib (ver 1.2.8)
JPEG: libjpeg (ver 90)
WEBP: build (ver 0.3.1)
PNG: build (ver 1.6.24)
TIFF: build (ver 42 - 4.0.2)
JPEG 2000: build (ver 1.900.1)
OpenEXR: build (ver 1.7.1)
GDAL: NO
GDCM: NO
Video I/O:
DC1394 1.x: NO
DC1394 2.x: NO
FFMPEG: NO
avcodec: NO
avformat: NO
avutil: NO
swscale: NO
avresample: NO
GStreamer: NO
OpenNI: NO
OpenNI PrimeSensor Modules: NO
OpenNI2: NO
PvAPI: NO
GigEVisionSDK: NO
Aravis SDK: NO
UniCap: NO
UniCap ucil: NO
V4L/V4L2: NO/NO
XIMEA: NO
Xine: NO
gPhoto2: NO
Parallel framework: pthreads
Other third-party libraries:
Use IPP: NO
Use IPP Async: NO
Use VA: NO
Use Intel VA-API/OpenCL: NO
Use Lapack: NO
Use Eigen: NO
Use Cuda: NO
Use OpenCL: YES
Use OpenVX: NO
Use custom HAL: NO
OpenCL: <Dynamic loading of OpenCL library>
Include path: /io/opencv/3rdparty/include/opencl/1.2
Use AMDFFT: NO
Use AMDBLAS: NO
Python 2:
Interpreter: python (ver 2.7.13)
Libraries:
numpy: /opt/python/cp27-cp27mu/lib/python2.7/site-packages/numpy/core/include (ver 1.11.1)
packages path: /opt/python/cp27-cp27mu/lib/python2.7/site-packages
Python 3:
Interpreter: NO
Python (for build): python
Java:
ant: NO
JNI: NO
Java wrappers: NO
Java tests: NO
Matlab: Matlab not found or implicitly disabled
Tests and samples:
Tests: NO
Performance tests: NO
C/C++ Examples: NO
Install path: /usr/local
cvconfig.h is in: /io/opencv/build
-----------------------------------------------------------------
安装官方给出的建议,重新编译,特别注意一些开关要设置下:
sudo apt-get -y install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils libtiff5-dev libjpeg62-dev ffmpeg libatlas-base-dev gfortran
cmake
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D FORCE_VTK=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D WITH_CUBLAS=ON \
-D CUDA_NVCC_FLAGS="-D_FORCE_INLINES" \
-D WITH_GDAL=ON \
-D WITH_XINE=ON \
-D BUILD_EXAMPLES=ON \
-D WITH_FFMPEG=ON ..
make -j32
make install
但是我发现,在重新编译后安装后的cv2.so
,引入到python后得到的信息如下:
GUI:
QT 4.x: YES (ver 4.8.7 EDITION = OpenSource)
QT OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libQtOpenGL.so)
OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGL.so)
VTK support: NO
Media I/O:
ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
WEBP: build (ver 0.3.1)
PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.6)
JPEG 2000: /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
GDAL: NO
GDCM: NO
Video I/O:
DC1394 1.x: NO
DC1394 2.x: YES (ver 2.2.4)
FFMPEG: YES
avcodec: YES (ver 56.60.100)
avformat: YES (ver 56.40.101)
avutil: YES (ver 54.31.100)
swscale: YES (ver 3.1.101)
avresample: NO
GStreamer:
base: YES (ver 0.10.36)
video: YES (ver 0.10.36)
app: YES (ver 0.10.36)
riff: YES (ver 0.10.36)
pbutils: YES (ver 0.10.36)
OpenNI: NO
OpenNI PrimeSensor Modules: NO
OpenNI2: NO
PvAPI: NO
GigEVisionSDK: NO
Aravis SDK: NO
UniCap: NO
UniCap ucil: NO
V4L/V4L2: NO/YES
XIMEA: NO
Xine: NO
gPhoto2: NO
Parallel framework: TBB (ver 4.4 interface 9002)
Other third-party libraries:
Use IPP: 9.0.1 [9.0.1]
at: /home/gwang/opencv-3.2.0/build/3rdparty/ippicv/ippicv_lnx
Use IPP Async: NO
Use VA: NO
Use Intel VA-API/OpenCL: NO
Use Lapack: YES (/opt/intel/mkl/lib/intel64/libmkl_core.so /opt/intel/mkl/lib/intel64/libmkl_intel_lp64.so /opt/intel/mkl/lib/intel64/libmkl_sequential.so /opt/intel/mkl/lib/intel64/libmkl_core.so /opt/intel/mkl/lib/intel64/libmkl_intel_lp64.so /opt/intel/mkl/lib/intel64/libmkl_sequential.so /opt/intel/mkl/lib/intel64/libmkl_core.so /opt/intel/mkl/lib/intel64/libmkl_intel_lp64.so /opt/intel/mkl/lib/intel64/libmkl_sequential.so -lpthread -lm -ldl)
Use Eigen: NO
Use Cuda: YES (ver 8.0)
Use OpenCL: YES
Use OpenVX: NO
Use custom HAL: NO
NVIDIA CUDA
Use CUFFT: YES
Use CUBLAS: YES
USE NVCUVID: NO
NVIDIA GPU arch: 20 30 35 37 50 52 60 61
NVIDIA PTX archs:
Use fast math: NO
OpenCL: <Dynamic loading of OpenCL library>
Include path: /home/gwang/opencv-3.2.0/3rdparty/include/opencl/1.2
Use AMDFFT: NO
Use AMDBLAS: NO
Python 2:
Interpreter: /usr/bin/python2.7 (ver 2.7.12)
Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
numpy: /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
packages path: lib/python2.7/dist-packages
Python 3:
Interpreter: /usr/bin/python3 (ver 3.5.2)
Python (for build): /usr/bin/python2.7
Java:
ant: NO
JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
Java wrappers: NO
Java tests: NO
Matlab:
mex: /usr/local/MATLAB/R2014a/bin/mex
Compiler/generator: Not working (bindings will not be generated)
Documentation:
Doxygen: NO
Tests and samples:
Tests: YES
Performance tests: YES
C/C++ Examples: YES
Install path: /usr/local
cvconfig.h is in: /home/gwang/opencv-3.2.0/build
-----------------------------------------------------------------
同样在终端内python控制台得到的information和.py文件内得到information居然不一样,仔细分析发现这两个不是一个东西,想想是不是通过其他方式安装了opencv,通过尝试如下命令发现了这个bug:
sudo pip uninstall opencv-python
The directory '/home/xxx/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling opencv-python-3.2.0.7:
/home/xxx/.local/LICENSE-3RD-PARTY.txt
/home/xxx/.local/LICENSE.txt
/home/xxx/.local/lib/python2.7/site-packages/cv2/__init__.py
/home/xxx/.local/lib/python2.7/site-packages/cv2/__init__.pyc
/home/xxx/.local/lib/python2.7/site-packages/cv2/cv2.so
/home/xxx/.local/lib/python2.7/site-packages/opencv_python-3.2.0.7.dist-info/DESCRIPTION.rst
/home/xxx/.local/lib/python2.7/site-packages/opencv_python-3.2.0.7.dist-info/INSTALLER
/home/xxx/.local/lib/python2.7/site-packages/opencv_python-3.2.0.7.dist-info/METADATA
/home/xxx/.local/lib/python2.7/site-packages/opencv_python-3.2.0.7.dist-info/RECORD
/home/xxx/.local/lib/python2.7/site-packages/opencv_python-3.2.0.7.dist-info/WHEEL
/home/xxx/.local/lib/python2.7/site-packages/opencv_python-3.2.0.7.dist-info/metadata.json
/home/xxx/.local/lib/python2.7/site-packages/opencv_python-3.2.0.7.dist-info/top_level.txt
Proceed (y/n)?
y
Successfully uninstalled opencv-python-3.2.0.7
The directory '/home/xx/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
卸载后,到终端python命令行内进行测试:
>>>python
>>>import cv2
>>>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
没有找到cv2,那么要把编译安装后的cv2.so重新链接下:
cd /usr/local/lib/python2.7/dist-packages
sudo ln -s /home/xxx/opencv3.2/build/lib/cv2.so cv2.so
至此,终于搞定这个问题!!