ubuntu 14.04上安装opencv 2.4.13

前端之家收集整理的这篇文章主要介绍了ubuntu 14.04上安装opencv 2.4.13前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、下载opencv2.4.13的.zip包

http://opencv.org/downloads.html

2. 解压到任意目录

[plain] view plain copy
  1. unzipopencv-2.4.13.zip

3.在解压后的目录里创建一个release

cdopencv-2.4.13

  • mkdirrelease
  • 3. 安装一些必要的依赖库(pkg-config非必须)

    sudoapt-getinstallbuild-essentialcmakelibgtk2.0-devpkg-configPython-devpython-numpylibavcodec-devlibavformat-devlibswscale-dev

    4. 编译opencv-2.4.13并且lib文件都会被安装到/usr/local目录下

    cdrelease

  • cmake-DCMAKE_BUILD_TYPE=RELEASE-DCMAKE_INSTALL_PREFIX=/usr/local-DWITH_TBB=ON-DBUILD_NEW_PYTHON_SUPPORT=ON-DWITH_V4L=ON-DWITH_QT=ON-DWITH_OPENGL=ON-DENABLE_FAST_MATH=1-DCUDA_FAST_MATH=1-DWITH_CUBLAS=1..
  • 如果出现提示qt5相关的错误,请安装qt5

    I was able to solve this by usingsudo apt-get install qt5-default


    不想要cuda的同学可以加上 -D WITH_CUDA=OFF节省大量时间

    caution: if "Error compiling OpenCV,fatal error: stdlib.h: No such file or directory" happens,then add follows todisable pre-compiled headers:

    -D ENABLE_PRECOMPILED_HEADERS=OFF


    5. install
    make-j8//建议多线程编译.单线程超慢
  • sudomakeinstall

  • 6. 查看pkg-config配置(非必须)
    pkg-config--libsopencv
  • pkg-config--cflagsopencv

  • 7. 在etc/ld.so.conf.d/目录下新建一个文件opencv.conf。加入opencv中lib的路径,我这里是/usr/local/lib。然后
    sudoldconfig-v

    8. 写一个test程序来测试opencv是否安装成功
    #include<opencv2/opencv.hpp>
  • usingnamespacecv;
  • intmain(intargc,char**argv)
  • {
  • Matimg=imread(argv[1]);
  • namedWindow("test",CV_WINDOW_AUTOSIZE);
  • imshow("test",img);
  • waitKey(0);
  • return0;
  • }

  • 9. 编译
    g++test.cpp-L/usr/local/lib`pkg-config--libsopencv--cflagsopencv`-otest

    未安装pkg-config的同学用如下:

    g++test.cpp-Wl,-rpath=/usr/local/lib-I/usr/local/include/-L/usr/local/lib-lopencv_core-lopencv_highgui-lopencv_imgproc-otest


    10. 运行
    ./testtest.jpg

  • I was able to solve this by usingsudo apt-get install qt5-default

    猜你在找的Ubuntu相关文章