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

简介: <h1 style="text-align:center">图文详解OpenCV在Jetson TK1上的安装和使用</h1> <p><br></p> <p>        本文介绍如何在Jetson TK1上安装并且使用OpenCV,并给出了示例,供大家参考学习。</p> <p><br></p> <h2>1、Jetson TK1平台的OpenCV优化包下载</h2> <p><b

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


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


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


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

如下图所示


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




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




sudo apt-add-repository universe
sudo apt-get update

3、安装OpenCV优化包




sudo dpkg -i libopencv4tegra_2.4.8.2_armhf.deb
sudo dpkg -i libopencv4tegra-dev_2.4.8.2_armhf.deb

4、安装一些函数库




# Some general development libraries
sudo apt-get install build-essential make cmake cmake-curses-gui g++
# libav video input/output development libraries
sudo apt-get install libavformat-dev libavutil-dev libswscale-dev
# Video4Linux camera development libraries
sudo apt-get install libv4l-dev
# Eigen3 math development libraries
sudo apt-get install libeigen3-dev
# OpenGL development libraries (to allow creating graphical windows)
sudo apt-get install libglew1.6-dev
# GTK development libraries (to allow creating graphical windows)
sudo apt-get install libgtk2.0-dev

5、下载OpenCV源码


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

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

wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
下载成功后见下图:



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





cd Downloads
unzip opencv-2.4.9.zip
mv opencv-2.4.9 ~

cd ~/opencv-2.4.9
mkdir build
cd build

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:):

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":

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:

echo "# Use OpenCV and other custom-built libraries." >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/" >> ~/.bashrc
source ~/.bashrc






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


# Make sure we have installed a C++ compiler.
sudo apt-get install build-essential g++

第一个示例:

# 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.
cd ~/opencv-2.4.9/samples/cpp
g++ edge.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -o edge
./edge


第二个示例:

# If you have a USB webcam plugged in to your board, then test one of the live camera programs.
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

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

第三个示例:

# Test a GPU accelerated OpenCV sample.
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的实验结果如下图:

最终的处理结果见下面的三个图:分别是原图、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

相关实践学习
部署Stable Diffusion玩转AI绘画(GPU云服务器)
本实验通过在ECS上从零开始部署Stable Diffusion来进行AI绘画创作,开启AIGC盲盒。
目录
相关文章
|
2月前
|
并行计算 PyTorch TensorFlow
Ubuntu安装笔记(一):安装显卡驱动、cuda/cudnn、Anaconda、Pytorch、Tensorflow、Opencv、Visdom、FFMPEG、卸载一些不必要的预装软件
这篇文章是关于如何在Ubuntu操作系统上安装显卡驱动、CUDA、CUDNN、Anaconda、PyTorch、TensorFlow、OpenCV、FFMPEG以及卸载不必要的预装软件的详细指南。
4564 3
|
2月前
|
计算机视觉
Opencv学习笔记(八):如何通过cv2读取视频和摄像头来进行人脸检测(jetson nano)
如何使用OpenCV库通过cv2模块读取视频和摄像头进行人脸检测,并提供了相应的代码示例。
107 1
|
2月前
|
缓存 并行计算 Ubuntu
Jetson 学习笔记(十一):jetson agx xavier 源码编译ffmpeg(3.4.1)和opencv(3.4.0)
本文是关于在Jetson AGX Xavier上编译FFmpeg(3.4.1)和OpenCV(3.4.0)的详细教程,包括编译需求、步骤、测试和可能遇到的问题及其解决方案。还提供了Jetson AGX Xavier编译CUDA版本的OpenCV 4.5.0的相关信息。
78 4
Jetson 学习笔记(十一):jetson agx xavier 源码编译ffmpeg(3.4.1)和opencv(3.4.0)
|
2月前
|
Ubuntu 应用服务中间件 nginx
Ubuntu安装笔记(三):ffmpeg(3.2.16)源码编译opencv(3.4.0)
本文是关于Ubuntu系统中使用ffmpeg 3.2.16源码编译OpenCV 3.4.0的安装笔记,包括安装ffmpeg、编译OpenCV、卸载OpenCV以及常见报错处理。
181 2
Ubuntu安装笔记(三):ffmpeg(3.2.16)源码编译opencv(3.4.0)
|
2月前
|
Ubuntu Linux C语言
Ubuntu安装笔记(二):ubuntu18.04编译安装opencv 3.4.0 opencv_contrib3.4.0
本文介绍了在Ubuntu 18.04系统上编译安装OpenCV 3.4.0及其扩展包opencv_contrib 3.4.0的详细步骤,包括下载源码、安装依赖、配置CMake和编译安装,以及常见问题的解决方法。
175 1
Ubuntu安装笔记(二):ubuntu18.04编译安装opencv 3.4.0 opencv_contrib3.4.0
|
2月前
|
PyTorch TensorFlow 算法框架/工具
Jetson环境安装(一):Ubuntu18.04安装pytorch、opencv、onnx、tensorflow、setuptools、pycuda....
本文提供了在Ubuntu 18.04操作系统的NVIDIA Jetson平台上安装深度学习和计算机视觉相关库的详细步骤,包括PyTorch、OpenCV、ONNX、TensorFlow等。
80 1
Jetson环境安装(一):Ubuntu18.04安装pytorch、opencv、onnx、tensorflow、setuptools、pycuda....
yolov5项目如何安装pycocotools和opencv-python?
本文提供了解决yolov5项目中安装pycocotools和opencv-python包失败的两种方法:手动安装或使用国内镜像源进行安装。
yolov5项目如何安装pycocotools和opencv-python?
|
4月前
|
前端开发 计算机视觉
Building wheel for opencv-python (pyproject.toml) ,安装命令增加 --verbose 参数
Building wheel for opencv-python (pyproject.toml) ,安装命令增加 --verbose 参数
215 2
|
6月前
|
机器学习/深度学习 算法 Java
计算机视觉——opencv快速入门(一) opencv的介绍与安装
OpenCV是开源计算机视觉库,支持C++, Python, Java等,用于图像处理、视频分析等。建议使用较早版本如3.4.3,因高版本部分算法需付费。通过Anaconda创建Python虚拟环境来安装,选择合适的Python和OpenCV版本。激活环境后,用`pip`安装`opencv-python`。基本环境配置完成后,通过显示图像的Python代码测试安装是否成功。
计算机视觉——opencv快速入门(一) opencv的介绍与安装
|
6月前
|
机器学习/深度学习 人工智能 自然语言处理
OpenCV与AI深度学习之常用AI名词解释学习
AGI:Artificial General Intelligence (通用人工智能):是指具备与人类同等或超越人类的智能,能够表现出正常人类所具有的所有智能行为。又被称为强人工智能。
137 2