在树莓派3 Ubuntu 16.04 Mate中安装OpenCV

前端之家收集整理的这篇文章主要介绍了在树莓派3 Ubuntu 16.04 Mate中安装OpenCV前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1. Install OpenCV in Ubuntu:

(1) Update the list of package repositories:


  1. sudoapt-getupdate
  2. sudoapt-getupgrade

(2) Remove prevIoUsly installed FFMPEG and x264 libraries:


  1. sudoapt-getremoveffmpegx264-dev

(3) Install the necessary packages for compiling the OpenCV sources:

  1. sudoapt-getinstallocl-icd-libopencl1build-essentialcheckinstallcmakepkg-configyasmlibjpeg-devlibjasper-devlibavcodec-devlibavformat-devlibswscale-devlibdc1394-22-devlibxine2-devlibgstreamer0.10-devlibgstreamer-plugins-base0.10-devlibv4l-devpython-devpython-numpylibtbb-devlibqt4-devlibgtk2.0-devlibfaac-devlibmp3lame-devlibopencore-amrnb-devlibopencore-amrwb-devlibtheora-devlibvorbis-devlibxvidcore-devx264v4l-utils

(4) Make a directory to download and build OpenCV:


  1. mkdiropencv
  2. cdopencv

(5) Download the OpenCV sources for Linux,then unzip it:


  1. wget-Oopencv-2.4.10.ziphttp://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip/download
  2. unzipopencv-2.4.10.zip
  3. cdopencv-2.4.10

(6) Create a directory to compile the OpenCV sources:


  1. mkdirbuild
  2. cdbuild

(7) Building OpenCV sources with CMake and install:


  1. cmake-DCMAKE_BUILD_TYPE=RELEASE-DCMAKE_INSTALL_PREFIX=/usr/local-DWITH_TBB=ON-DINSTALL_PYTHON_EXAMPLES=ON-DBUILD_EXAMPLES=ON-DWITH_QT=ON-DWITH_OPENGL=ON..


(8) Make and install:


  1. make
  2. sudomakeinstall
  3. sudosh-c'echo"/usr/local/lib">/etc/ld.so.conf.d/opencv.conf'
  4. sudoldconfig

(9) Restart the system for everything to take effect:


  1. sudoshutdown-rnow


2. Test OpenCV in Ubuntu:

(1) Create a directory DisplayImage for test project:


  1. mkdirDisplayImage
  2. cdDisplayImage

(2) Create DisplayImage.cpp and edit it:


  1. geditDisplayImage.cpp

Then edit the DisplayImage.cpp:


  1. #include<stdio.h>
  2. #include<opencv2/opencv.hpp>
  3. usingnamespacecv;
  4. intmain(intargc,char**argv)
  5. {
  6. if(argc!=2)
  7. {
  8. printf("usage:DisplayImage.out<Image_Path>\n");
  9. return-1;
  10. }
  11. Matimage;
  12. image=imread(argv[1],1);
  13. if(!image.data)
  14. {
  15. printf("Noimagedata\n");
  16. return-1;
  17. }
  18. namedWindow("DisplayImage",CV_WINDOW_AUTOSIZE);
  19. imshow("DisplayImage",image);
  20. waitKey(0);
  21. return0;
  22. }

(3) Create a CMake file:


  1. geditCMakeLists.txt

Then edit the CMakeLists.txt:


  1. cmake_minimum_required(VERSION2.8)
  2. project(DisplayImage)
  3. find_package(OpenCVrequired)
  4. add_executable(DisplayImageDisplayImage.cpp)
  5. target_link_libraries(DisplayImage${OpenCV_LIBS})

(4) Generate the executable file:


  1. cmake.
  2. make

(5) Execute it:


  1. ./DisplayImagelena.jpg

lena.jpg is the test image



ffmpeg error:

cmake ........ -D WITH_FFMPEG=OFF

原文链接:https://www.f2er.com/ubuntu/352988.html

猜你在找的Ubuntu相关文章