Main Content

Deploy and Run Fog Rectification for Video on NVIDIA Jetson

这个例子展示了如何生成和部署一个铜DA® executable for a video-based fog rectification application. The example shows the deployable code generation capabilities that the MATLAB® Coder™ Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms provides for the MATLABVideoReader功能。此示例生成了一个CUDA应用程序,该应用程序读取视频文件的内容,执行雾化整流操作,并在NVIDIA®硬件上显示输出视频。

先决条件

目标板要求

  • NVIDIA JETSON嵌入式平台。

  • Ethernet crossover cable to connect the target board and host PC (if the target board cannot be connected to a local network).

  • 目标上的GSTREAMER和SDL库。

  • 编译器和库的目标上的环境变量。有关更多信息,请参阅NVIDIA董事会的安装和设置先决条件

  • 连接到目标显示端口的监视器。

开发主机要求

Create a Folder and Copy Relevant Files

这following line of code creates a folder in your current working folder on the host and copies all the relevant files into this folder. If you cannot generate files in this folder, before running this command, change your current working folder.

nvidiademo_setup('fog_rectification_videoreader');

Connect to the NVIDIA Hardware

这support package uses an SSH connection over TCP/IP to execute commands while building and running the generated CUDA code on the Jetson platforms. Connect the target platform to the same network as the host computer or use an Ethernet crossover cable to connect the board directly to the host computer. For information on how to set up and configure your board, see NVIDIA documentation.

要与NVIDIA硬件进行通信,请通过使用该实时硬件连接对象杰森功能。您必须知道目标板的主机名或IP地址,用户名和密码,以创建实时硬件连接对象。例如,首次连接到目标板时,使用命令:为Jetson硬件创建一个实时对象:

hwobj = jetson('jetson-tx2-name',,,,'ubuntu',,,,'ubuntu');

During the hardware live object creation, the support package performs hardware and software checks, IO server installation, and gathers peripheral information on target. This information is displayed in the Command Window.

验证目标板上的GPU环境

To verify that the compilers and libraries necessary for running this example are set up correctly, use thecoder.checkGpuInstall(GPU Coder)功能。

envcfg = coder.gpuenvconfig('jetson');envcfg.basiccodegen = 1;envcfg.quiet = 1;envcfg.hardwareObject = hwobj;coder.checkgpuinstall(envcfg);

fog_rectification入口点功能

fog_rectification.m功能将有雾的视频作为输入,并显示defoggoggog的视频。

functionfog_rectification()%#codegen%版权2019-2021 The Mathworks,Inc。coder.gpu.kernelfun; hwobj = jetson(); width = 600; height = 404; videoFileName ='foggy.mp4';vobj = videoreader(hwobj,videofileName,'Width',宽度,'Height',,,,height);whilevobj.hasframe input = vobj.readframe;% Run fog rectification on the frameout = fog_rectification_algorithm(输入,宽度,高度);结尾结尾

准备雾化申请

Include theVideoReaderand display interfaces inside the fog rectification application for code generation.

hwobj = jetson; videoFileName ='foggy.mp4';vobj = videoreader(hwobj,videofileName,'Width',,,,640,'Height',480);dispobj = imagedisplay(hwobj);

这video file name input accepts full and relative paths. For code generation, provide the video file path on the target. For example, if the video file is available at the location'/home/ubuntu/video/foggy.mp4',,,,then you must provide this path.

使用GPU编码器为目标板生成CUDA代码

To generate a CUDA executable that you can deploy on to an NVIDIA target, create a GPU code configuration object for generating an executable.

cfg = coder.gpuconfig('可执行程序');

To create a configuration object for the Jetson platform and assign it to the硬件property of the code configuration objectCFG, 使用coder.hardware功能。

cfg.hardware = coder.hardware('nvidia jetson');

To specify the folder for performing remote build process on the target board, use theBuildDir财产。如果目标板上不存在指定的构建文件夹,则该软件将创建带有给定名称的文件夹。如果未分配给CFG。硬件。BuildDir,远程构建过程发生在最后指定的构建文件夹中。如果没有存储的构建文件夹值,则在主文件夹中进行构建过程。

cfg.hardware.builddir ='〜/remoteBuildDir';

设置GenerateExampleMain属性生成示例C ++主文件并进行编译。此示例不需要对生成的主文件进行修改。

cfg.generateExamPlemain =“ generateCodeAndCompile';

To generate CUDA code, use the代码根功能并传递GPU代码配置和输入的大小fog_rectificationentry-point function. After the code generation takes place on the host, the generated files are copied over and built on the target.

Codegen(Codegen)('-config',CFG,'fog_rectification',,,,'-report');

Copy Video File onto Target Board

将视频文件移至目标板。

putfile(hwobj,'foggy.mp4',,,,hwobj.workspaceDir);

在目标板上运行雾化

To run the generated executable on the target board, use the MATLABRunApplication功能。

pid = runApplication(hwobj,'fog_rectification');

窗口在目标硬件显示屏上打开,显示了录制视频的雾化矫正输出。

清理

要删除示例文件并返回原始文件夹,请致电cleanup功能。

cleanup