在树莓派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

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...