在Ubuntu 12.04上安装OpenCV

时间:2014-05-15 05:02:39

标签: opencv ubuntu ubuntu-12.04

我正在尝试在Ubuntu上安装OpenCV 2.4.2并遇到如下错误:

[ 11%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_gtk.cpp.o
In file included from /usr/local/include/glib-2.0/glib/gasyncqueue.h:30:0,
             from /usr/local/include/glib-2.0/glib.h:32,
             from /usr/local/include/gtk-2.0/gdk/gdktypes.h:32,
             from /usr/local/include/gtk-2.0/gdk/gdkcolor.h:4,
             from /usr/local/include/gtk-2.0/gdk/gdk.h:30,
             from /usr/local/include/gtk-2.0/gtk/gtk.h:31,
             from /opt/opencv/OpenCV-2.4.2/modules/highgui/src/window_gtk.cpp:48:
/usr/local/include/glib-2.0/glib/gthread.h:233:27: error: variable or field 'g_static_mutex_init' declared void
/usr/local/include/glib-2.0/glib/gthread.h:233:27: error: 'GStaticMutex' was not declared in this scope
/usr/local/include/glib-2.0/glib/gthread.h:233:41: error: 'mutex' was not declared in this scope
/usr/local/include/glib-2.0/glib/gthread.h:233:41: note: suggested alternative:
/usr/include/tbb/mutex.h:48:7: note:   'tbb::mutex'

我检查了所有依赖项并按如下方式安装它们:

sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev

我还将以下路径添加到CMakeCache.txt

CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include/

感谢任何帮助。

谢谢,

西特

编辑:我根据评论切换到QT,这让我摆脱了我必须手动插入CMakeCache.txt的gtk包含。但是我仍然遇到安装错误(可能是由于glib包含)所以我在CMAKE中关闭了GSTREAMER,现在我可以安装opencv了。这项工作是否可行?

2 个答案:

答案 0 :(得分:1)

好奇当v2.4.9是最新版本时你需要v2.4.2。在任何情况下,在执行步骤之前输出build steps配置报告,如下所示:

--
-- General configuration for OpenCV 2.4.2 =====================================
--
--   Platform:
--     Host:                        Linux 3.8.0-29-generic x86_64
--     CMake:                       2.8.7
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++ (ver 4.6.3)
--     C++ flags (Release):         -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG -ggdb3
--     C Compiler:                  /usr/bin/gcc
--     C flags (Release):           -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG -ggdb3
--     Linker flags (Release):
--     Linker flags (Debug):
--     Precompiled headers:         NO
--
--   OpenCV modules:
--     To be built:                 core imgproc flann highgui features2d calib3d ml video objdetect contrib nonfree gpu legacy photo python stitching ts videostab
--     Disabled:                    -
--     Disabled by dependency:      -
--     Unavailable:                 androidcamera java world
--
--   GUI:
--     QT 4.x:                      NO
--     GTK+ 2.x:                    YES (ver 2.24.10)
--     GThread :                    YES (ver 2.32.4)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--
--   Media I/O:
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.3.4)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.46)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 3.9.5)
--     JPEG 2000:                   /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
--     OpenEXR:                     /usr/lib/libImath.so /usr/lib/libIlmImf.so /usr/lib/libIex.so /usr/lib/libHalf.so /usr/lib/libIlmThread.so (ver 1.6.1)
--
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.0)
--     FFMPEG:                      YES
--       codec:                     YES (ver 53.35.0)
--       format:                    YES (ver 53.21.1)
--       util:                      YES (ver 51.22.2)
--       swscale:                   YES (ver 2.1.0)
--       gentoo-style:              YES
--     GStreamer:                   NO
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     PvAPI:                       NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    Using libv4l (ver 0.8.6)
--     XIMEA:                       NO
--     Xine:                        NO
--
--   Other third-party libraries:
--     Use IPP:                     NO
--     Use TBB:                     NO
--     Use Cuda:                    NO
--     Use Eigen:                   YES (ver 2.0.17)
--
--   Python:
--     Interpreter:                 /usr/bin/python (ver 2.7.3)
--     Libraries:                   /usr/lib/libpython2.7.so
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.6.1)
--     packages path:               lib/python2.7/dist-packages
--
--   Documentation:
--     Build Documentation:         YES
--     Sphinx:                      /usr/bin/sphinx-build (ver 1.1.3)
--     PdfLaTeX compiler:           /usr/bin/pdflatex
--
--   Tests and samples:
--     Tests:                       YES
--     Performance tests:           YES
--     Examples:                    NO
--
--   Install path:                  /usr/local
--
--   cvconfig.h is in:              /home/vagrant/OpenCV-2.4.2/release
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vagrant/OpenCV-2.4.2/release

检查此报告是否有任何缺失的库并安装这些依赖项。

我能够从源代码构建并在ubuntu 12.04上安装您列出的依赖项时遇到错误:

... 
[ 13%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/window.cpp.o
[ 13%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_gtk.cpp.o
[ 13%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_dc1394_v2.cpp.o
[ 13%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_libv4l.cpp.o
[ 14%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_sunras.cpp.o
[ 14%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_pxm.cpp.o
[ 14%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_jpeg2000.cpp.o
[ 14%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_exr.cpp.o
[ 14%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_imageio.cpp.o
[ 15%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_jpeg.cpp.o
[ 15%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_base.cpp.o
[ 15%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_png.cpp.o
[ 15%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_bmp.cpp.o
[ 15%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_tiff.cpp.o
[ 15%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o
Linking CXX shared library ../../lib/libopencv_highgui.so
...

答案 1 :(得分:1)

除非您需要某些特定的编译选项,否则您应该可以直接从Synaptic(版本2.3.1)安装OpenCV;这些库已经存在于默认存储库中。

如果您需要更新版本,您还应该能够找到预编译OpenCV的一些PPA,例如https://launchpad.net/~yjwong/+archive/opencv2https://launchpad.net/~limparissoft/+archive/opencv-ppa

您可以在https://launchpad.net/ubuntu/+ppas?name_filter=opencv

中找到更多PPA