1. 程式人生 > >zynq-7000學習筆記(六)——HLS綜合FAST corner並匯出IP

zynq-7000學習筆記(六)——HLS綜合FAST corner並匯出IP

PC平臺:WINDOWS 10 64位

Xilinx設計開發套件:Xilinx_vivado_sdk_2015.2

開發板:Zed Board

一、開啟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<MAX_HEIGHT,MAX_WIDTH,HLS_8UC3>      _src(rows,cols);
	hls::Mat<MAX_HEIGHT,MAX_WIDTH,HLS_8UC3>      _dst(rows,cols);
#pragma HLS dataflow
	hls::AXIvideo2Mat(INPUT_STREAM, _src);
	hls::Mat<MAX_HEIGHT,MAX_WIDTH,HLS_8UC3>      src0(rows,cols);
	hls::Mat<MAX_HEIGHT,MAX_WIDTH,HLS_8UC3>      src1(rows,cols);
#pragma HLS stream depth=20000 variable=src1.data_stream
	hls::Mat<MAX_HEIGHT,MAX_WIDTH,HLS_8UC1>      mask(rows,cols);
	hls::Mat<MAX_HEIGHT,MAX_WIDTH,HLS_8UC1>      dmask(rows,cols);
	hls::Scalar<3,unsigned char> color(255,0,0);
	hls::Duplicate(_src,src0,src1);
	hls::Mat<MAX_HEIGHT,MAX_WIDTH,HLS_8UC1>      gray(rows,cols);
	hls::CvtColor<HLS_BGR2GRAY>(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<ap_axiu<32,1,1,1> >               AXI_STREAM;
typedef hls::Scalar<3, unsigned char>                 RGB_PIXEL;
typedef hls::Mat<MAX_HEIGHT, MAX_WIDTH, HLS_8UC3>     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目錄裡找到

程式碼