Zynq-7000学习笔记(六)——HLS综合FAST corner并导出IP

PC平台:WINDOWS 10 64位

Xilinx设计开发套件:Xilinx_vivado_sdk_2015.2

开发板:Zed Board

参考文档:XAPP1167          

参考代码:XAPP1167.zip

一、打开vivado hls的GUI界面,新建一个project,top function为hls_fast_corner

二、增加top.cpp,代码如下
#include "top.h"

void hls_fast_corner(AXI_STREAM& INPUT_STREAM, AXI_STREAM& OUTPUT_STREAM, int rows, int cols, int threhold)
{
//Create AXI streaming interfaces for the core
#pragma HLS INTERFACE axis port=INPUT_STREAM
#pragma HLS INTERFACE axis port=OUTPUT_STREAM

#pragma HLS RESOURCE core=AXI_SLAVE variable=rows metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=cols metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=threhold metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE core=AXI_SLAVE variable=return metadata="-bus_bundle CONTROL_BUS"

#pragma HLS INTERFACE ap_stable port=rows
#pragma HLS INTERFACE ap_stable port=cols
#pragma HLS INTERFACE ap_stable port=threhold

hls::Mat _src(rows,cols);
hls::Mat _dst(rows,cols);
#pragma HLS dataflow
hls::AXIvideo2Mat(INPUT_STREAM, _src);
hls::Mat src0(rows,cols);
hls::Mat src1(rows,cols);
#pragma HLS stream depth=20000 variable=src1.data_stream
hls::Mat mask(rows,cols);
hls::Mat dmask(rows,cols);
hls::Scalar<3,unsigned char> color(255,0,0);
hls::Duplicate(_src,src0,src1);
hls::Mat gray(rows,cols);
hls::CvtColor(src0,gray);
hls::FASTX(gray,mask,threhold,true);
hls::Dilate(mask,dmask);
hls::PaintMask(src1,dmask,_dst,color);
hls::Mat2AXIvideo(_dst, OUTPUT_STREAM);
}

top.h如下
#ifndef _TOP_H_
#define _TOP_H_

#include "hls_video.h"

// maximum image size
#define MAX_WIDTH 1920
#define MAX_HEIGHT 1080

// I/O Image Settings
#define INPUT_IMAGE "test1.bmp"
#define OUTPUT_IMAGE "result.bmp"
#define OUTPUT_IMAGE_GOLDEN "result_golden.bmp"

// typedef video library core structures
typedef hls::stream > AXI_STREAM;
typedef hls::Scalar<3, unsigned char> RGB_PIXEL;
typedef hls::Mat RGB_IMAGE;

// top level function for HW synthesis
void hls_fast_corner(AXI_STREAM& src_axi, AXI_STREAM& dst_axi, int rows, int cols, int threhold);

#endif

增加test.cpp
#include "top.h"
#include "hls_opencv.h"
#include "iostream"

int main (int argc, char** argv) {

IplImage* src = cvLoadImage(INPUT_IMAGE);
IplImage* dst = cvCreateImage(cvGetSize(src), src->depth, src->nChannels);

AXI_STREAM src_axi, dst_axi;
IplImage2AXIvideo(src, src_axi);

hls_fast_corner(src_axi, dst_axi, src->height, src->width, 20);

AXIvideo2IplImage(dst_axi, dst);

cvSaveImage(OUTPUT_IMAGE, dst);

return 0;
}

添加一个测试图片,图片文件名必须和top.h定义的INPUT_IMAGE一样


三、综合

四、导出IP,在vivado可以看到如下具有接口的hls_fast_corner

五、执行c cosimulation,测试输出的文件可以在solution1\sim\wrapc_pc目录里找到

代码

来源:luotong86的专栏
*本文已由作者授权转发,如需转载请联系作者本人获得授权