1、在NVIDIA Jetson TK1 上安装opencv有两种方式(WIKI_NVIDIA: http://elinux.org/Jetson/Installing_OpenCV ),第一种,安装英伟达为TK1定制的软件包系统L4T中的opencv,但是这种方法有缺点:由于商业专利的问题,其带的opencv不包含SIFT,SURF等图像特征提取算法;同时不能选择OPENCV的版本。第二种方法:自己下载需要的OPENCV源码进行编译安装。
2、根据orb-slam作者的源码,最好选择安装OpenCV2.4.11版本,避免不必要的坑。ubuntu14.04
3、安装:选择源码安装opencv2.4.11
(1)打开通用存储库,并更新update
sudo add-apt-repository universe sudo apt-get update
(2)安装依赖库:
# Some general development libraries sudo apt-get -y install build-essential make cmake cmake-curses-gui g++ # libav video input/output development libraries sudo apt-get -y install libavformat-dev libavutil-dev libswscale-dev # Video4Linux camera development libraries sudo apt-get -y install libv4l-dev # Eigen3 math development libraries sudo apt-get -y install libeigen3-dev # OpenGL development libraries (to allow creating graphical windows) sudo apt-get -y install libglew1.6-dev # GTK development libraries (to allow creating graphical windows) sudo apt-get -y install libgtk2.0-dev
(3)下载opencv源码:
如果需要下载自己需要的版本,只需把网址链接中的所有2.4.11改为你需要的版本号即可。
进入Download文件夹:cd ~/Download
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.11/opencv-2.4.11.zip
(4)解压opencv压缩包:并把解压文件移到home文件夹下
cd Downloads unzip opencv-2.4.11.zip mv opencv-2.4.11 ~
(5)使用Cmake编译opencv源码:
cd ~/opencv-2.4.11 mkdir build cd build cmake -DWITH_CUDA=ON -DCUDA_ARCH_BIN="3.2" -DCUDA_ARCH_PTX="" -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF ..
编译成功的结果:
(6)为了安装opencv库时使用TK1的4个CPU核,同时复制opencv库文件到"/usr/local/include" 以及"/usr/local/lib",我们使用如下命令进行快速安装,约40分钟:
sudo make -j4 install
安装成功的截图如下:
(7)添加环境变量,使得操作系统能找到你所安装的OpenCV库文件:
echo "# Use OpenCV and other custom-built libraries." >> ~/.bashrc echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/" >> ~/.bashrc source ~/.bashr
(8)测试OpenCV。首先确认你已经安装了C++编译器。
# Make sure we have installed a C++ compiler. sudo apt-get install build-essential g++
A、例子一:测试边缘提取算法
cd ~/opencv-2.4.11/samples/cpp g++ edge.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -o edge ./edge测试结果如下:
B、例子二:通过USB摄像头采集视频,实现拉普拉斯变换
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 ./laplace测试结果如下:
C、例子三:测试OpenCV的GPU模块是否安装好,检测图像中的线段。
cd ../gpu 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
./houghlines ../cpp/logo_in_clutter.png
原始图像:
CPU提取结果:
GPU提取结果:
如果所有的安装步骤都正确,且上述三个实验没有错误,那么OpenCV2.4.11在NVIDIA Jetson TK1上安装成功!