NVIDIA Jetson TK1学习与开发(七):图文详解OpenCV在Jetson TK1上的安装和使用

图文详解OpenCV在Jetson TK1上的安装和使用


        本文介绍如何在Jetson TK1上安装并且使用OpenCV,并给出了示例,供大家参考学习。


1、Jetson TK1平台的OpenCV优化包下载


下载地址:https://developer.nvidia.com/linux-tegra-rel-19(需要注册才可以下载)

如下图所示


下载后拷贝到TK1平台中,如下图所示




2、使能通用存储库和更新apt-get




[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. sudo apt-add-repository universe  
  2. sudo apt-get update  

3、安装OpenCV优化包




[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. sudo dpkg -i libopencv4tegra_2.4.8.2_armhf.deb  
  2. sudo dpkg -i libopencv4tegra-dev_2.4.8.2_armhf.deb  

4、安装一些函数库




[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. # Some general development libraries  
  2. sudo apt-get install build-essential make cmake cmake-curses-gui g++  
  3. # libav video input/output development libraries  
  4. sudo apt-get install libavformat-dev libavutil-dev libswscale-dev  
  5. # Video4Linux camera development libraries  
  6. sudo apt-get install libv4l-dev  
  7. # Eigen3 math development libraries  
  8. sudo apt-get install libeigen3-dev  
  9. # OpenGL development libraries (to allow creating graphical windows)  
  10. sudo apt-get install libglew1.6-dev  
  11. # GTK development libraries (to allow creating graphical windows)  
  12. sudo apt-get install libgtk2.0-dev  

5、下载OpenCV源码


下载地址:http://opencv.org/(注意选择OpenCV for Linux/Mac

或者在TK1平台上直接下载,方法是:

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip  
下载成功后见下图:



6、解压OpenCV源码,并进行配置





[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. cd Downloads  
  2. unzip opencv-2.4.9.zip  
  3. mv opencv-2.4.9 ~  

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. cd ~/opencv-2.4.9  
  2. mkdir build  
  3. cd build  

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. cmake -DWITH_CUDA=ON -DCUDA_ARCH_BIN="3.2" -DCUDA_ARCH_PTX="" -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF  
自己也可以根据需要进行配置(If you want to customize any more of the build settings such as whether to support Firewire cameras or Qt GUI, it is easiest to use the curses interactive version of CMake from here on:):

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. ccmake ..  

7、 build & install OpenCV using a single command


Now you should be ready to build OpenCV and then install it. Unfortunately, OpenCV is currently experiencing a problem with CMake where installing the built libraries (that normally takes a few seconds) re-compiles the whole OpenCV (that normally takes close to an hour). So to save time, instead of running "make -j4 ; make install", we will build & install OpenCV using a single command.

To build & install the OpenCV library using all 4 Tegra CPU cores (takes around 40 minutes), including copying the OpenCV library to "/usr/local/include" and "/usr/local/lib":

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. sudo make -j4 install  


8、make sure your system searches the "/usr/local/lib" folder for libraries


Finally, make sure your system searches the "/usr/local/lib" folder for libraries:

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. echo "# Use OpenCV and other custom-built libraries." >> ~/.bashrc  
  2. echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/" >> ~/.bashrc  
  3. source ~/.bashrc  






9、测试OpenCV并运行几个例子


[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. # Make sure we have installed a C++ compiler.  
  2. sudo apt-get install build-essential g++  

第一个示例:

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. # Test a simple OpenCV program. Creates a graphical window, hence you should plug a HDMI monitor in or use a remote viewer such as X Tunneling or VNC or TeamViewer on your desktop.  
  2. cd ~/opencv-2.4.9/samples/cpp  
  3. g++ edge.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -o edge  
  4. ./edge  


第二个示例:

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. # If you have a USB webcam plugged in to your board, then test one of the live camera programs.  
  2. g++ laplace.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -o laplace  
  3. ./laplace  

(注意:此示例没有演示出来,待解决。。。,错误提示见上图。)

第三个示例:

[cpp]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. # Test a GPU accelerated OpenCV sample.  
  2. cd ../gpu  
  3. g++ houghlines.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -o houghlines  
  4. ./houghlines ../cpp/logo_in_clutter.png  


CPU与GPU的实验结果如下图:

最终的处理结果见下面的三个图:分别是原图、CPU处理后、GPU处理后的结果。




(If the houghlines GPU sample program worked then you have successfully installed OpenCV and its GPU module!)


10、更多参考学习资料


Using OpenCV with gcc and CMake

official opencv tutorials

OpenCV Reference Manual PDF file

©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页