Main Content

Corner Detection and Image Overlay with Zynq-Based Hardware

这个例子展示了如何目标detectio一角n algorithm to the Zynq® hardware using the Vision HDL Toolbox™ Support Package for Xilinx® Zynq-Based Hardware.

Required products:

  • Simulink®

  • 视觉HDL工具箱

  • 计算机视觉工具箱™

  • HDL Coder™

  • HDL Coder Support Package for Xilinx Zynq Platform

可选地,生成,编译和针对ZynqArm®软件生成模型:

  • 嵌入式编码器®

  • Xilinx Zynq平台的嵌金宝app入式编码器支持包

Introduction

This example follows the algorithm development workflow that is detailed in theDeveloping Vision Algorithms for Zynq-Based Hardware例子。如果您尚未这样做,请仔细研究该示例,以更好地了解所需的工作流程。

This algorithm corresponds to the Vision HDL Toolbox example,Harris Corner Detection。With the Support Package for Zynq-Based Vision Hardware, you get a hardware reference design that allows for easy integration of your targeted algorithm in the context of a vision system.

设置

如果您尚未这样做,请穿过Zynq支持软件包安装的指导设置向导部分。金宝app安装此支持包时,您可能已经完成了此步骤。金宝app

On the MATLABHometab, in theEnvironment部分Toolstrip,,,,clickAdd-Ons > Manage Add-Ons。定位Xilinx Zynq硬件的Visio金宝appn HDL工具箱支持包,然后单击设置

The guided setup wizard performs a number of initial setup steps, and confirms that the target can boot and that the host and target can communicate.

For more information, seeStep 1. Setup Checklist

Pixel-Stream Model

该模型提供了用于靶向HDL的算法的像素流实现。HDL准备就绪算法没有处理完整图像,而是在像素流界面上工作。该模型使用Image Resizeblock that allows the source video frame to be resized for better simulation performance. Alternatively, you may want to perform a crop of the video frame. The blocks in the shaded areas convert to and from pixel stream signals in preparation for targeting.

Video Source此示例的源视频来自From Multimedia File块,从多媒体文件读取视频数据,或视频截取block, that captures live video frames from an HDMI source connected to the Zynq-based hardware. To configure the source, right-click on the variant selection icon in the lower-left corner of the图像源block, chooseLabel mode active choice,,,,and select eitherFileorHW

对于此算法,该模型的配置如列出:

  • RGB的像素格式。该算法编写用于以RGB像素格式进行工作,两者都From Multimedia Fileand视频截取块配置为以这种格式交付视频帧。其他支持的像金宝app素格式是YCBCR 4:2:2,仅是y。

算法配置The algorithm, in addition to processing the image for corner detection has some control as well.

  • pbCornerOnlyconnects to a push button on the board to display the corner detection results without showing the original image.

  • cSliceLevelis a configuration option to adjust the corner detection threshold.

  • cOverlayColoris a configuration option to adjust the color of the corner markers.

  • coverlaytransp是一个配置选项调整混合啊f the original image and the corner detection image. A value of 255 means full original image and a 0 means full corner detection image.

定位后,cSliceLevel,,,,cOverlayColorandcoverlaytranspparameters are controllable from the Simulink model throughExternal ModeorTarget Hardware执行。pbCornerOnly控制端口是目标设计中的纯硬件连接。该端口可以以任何理想的速率运行,包括以像素时钟速率。

However,cSliceLevel,,,,coverlaytranspandcOverlayColor值由嵌入式处理器控制(或主机External ModeorTarget Hardwaremode). Because neither the host nor the embedded CPU can update these controls at the pixel clock rate, a rate on the order of the frame rate is desired. The sample times of the constant blocks attached to these controls are set to execute at theframeSampleTime

There are two things to note about the simulation outputs:

  1. During the first frame of simulation output, the Video Display scopes displays a black image. This condition indicates that no image data is available. This behavior is because the output of the pixel-streaming algorithm must be buffered to form a full-frame before being displayed.

  2. During the second frame of simulation, the Video Display scope for the pixel-streaming output is incorrect with respect to thecSliceLevelandcoverlaytransp您配置的Simulink模型的参数值。金宝app这种差异是因为该算法使用初始cSliceLevelandcoverlaytranspvalue of0。当您使用时Rate Transition配置的块Unit Delay模式以输入率以输入率后,输入值仅在输出后注册。在这种情况下,输入率对应于一个视频框架。在此初始过渡期间,该块将输出initial conditions(a value of0).These blocks are required to ensure a single-rate for all blocks within the subsystem, which is required for HDL code generation. For more information, seeRate Transition(金宝appSimulink)

You can optionally run this simulation without hardware. To modify the frame size for simulation performance, change theFrame size价值Image Resize,,,,图像框架到像素,,,,andImage Pixels To Frameblocks. The lower the frame size, the faster the simulation will run. The minimum frame size is 240p.

靶向算法

对像素流算法模拟感到满意后,您可以将像素算法定位到Zynq板上的FPGA。

In preparation for targeting, set up the Xilinx tool chain by invokinghdlsetuptoolpath。For example:

>> hdlsetuptooppath('ToolName',,,,'Xilinx Vivado',,,,'ToolPath',,,,'c:\ xilinx \ vivado \ 2020.2 \ bin \ vivado.bat');

Executehdlsetuptoolpath(HDL Coder)for more information.

Start the targeting workflow by right clicking the角覆盖算法subsystem and selectingHDL代码> HDL工作流顾问

  • In Step 1.1, selectIP Core Generation工作流并从列表中选择您的目标平台。

  • In Step 1.2, selectRGB参考设计匹配的像素格式角覆盖算法子系统。将硬件用户逻辑的其他端口映射到可用的硬件接口。对于此示例,映射pbCornerOnlyto push button 0. Likewise, mapcSliceLevel,,,,coverlaytranspandcOverlayColorto AXI4-Lite software control.

  • 步骤2通过进行一些设计检查来准备生成的设计。

  • 步骤3为IP核心生成HDL代码。

  • Step 4 integrates the newly generated IP core into the larger Vision Zynq reference design.

Execute each step in sequence to experience the full workflow, or, if you are already familiar with preparation and HDL code generation phases, right-click Step 4.1 in the table of contents on the left hand side and selectRun to selected task

  • 在步骤4.2中,工作流生成目标硬件接口模型,如果已安装了嵌入式编码器ZYNQ支持软件包,则是Zynq软件接口模型。金宝app点击Run this taskbutton with the default settings.

Steps 4.3 and 4.4

The rest of the workflow generates a bitstream for the FPGA, downloads it to the target, and reboots the board.

Because this process can take 20-40 minutes, you can choose to bypass this step by using a pre-generated bitstream for this example that ships with product and was placed on the SDCard during setup.

笔记:该比特流是用HDMI像素时钟约束至148.5 MHz生成的,每秒60帧时最大分辨率为1080p HDTV。要在Zynq硬件上以更高的分辨率运行此示例,请从步骤1.2中的下拉列表中选择源视频分辨率值。

To use this pre-generated bitstream execute the following:

>> vz = visionzynq();>> changefpgaimage(vz,'Visionzynq-Zedboard-HDMicam-Corner_overlay.bit');

要使用另一个平台的Bitstream,请用平台名称替换“ Zedboard”。

Alternatively, you can continue with Steps 4.3 and 4.4.

Using the Generated Models from the HDL Workflow Advisor

步骤4.2根据是否安装了嵌入式编码器,生成了两个或四个模型:“目标硬件接口”模型和关联的库模型以及“软件接口”模型和关联的库模型。“目标硬件接口”模型可用于控制Simulink模型的参考设计,而无需嵌入编码器。金宝app安装了嵌入式编码器和Zynq(嵌入式编码器)支持软件包时,“软金宝app件接口”模型支持针对Zynq的完整软件,并启用外部模式仿真,在循环中的处理器和完整部署。

The library models are created so that any changes to the hardware generation model are propagated to any custom targeted hardware simulation or software interface models that exist.

目标硬件接口模型:In this model, you can adjust the configuration of the reference design and read or drive control ports of the hardware user logic. These configuration changes affect the design while it is running on the target. You can also display captured video from the target device.

Software Interface Model:In this model, you can run in External mode to control the configuration of the reference design, and read or drive any control ports of the hardware user logic that you connected to AXI-Lite registers. These configuration changes affect the design while it is running on the target. You can use this model to fully deploy a software design. (This model is generated only if Embedded Coder and the Embedded Coder Zynq support package are installed.)