HLS第六课(HLS VIDEO LIBRARY)

D:\Xilinx\Vivado\2019.1\include

可以找到需要的H文件,从中可以查看系统函数
++++++++++++++++++++++++++++++++++++++++++++
ap_int.h

+++++++++++++++++++++++++++++++++++++++++
ap_axi_sdata.h

template<int D,int U,int TI,int TD>
  struct ap_axiu{
    ap_uint<D>       data;
    ap_uint<(D+7)/8> keep;
    ap_uint<(D+7)/8> strb;
    ap_uint<U>       user;
    ap_uint<1>       last;
    ap_uint<TI>      id;
    ap_uint<TD>      dest;
  };

++++++++++++++++++++++++++++++++++++++++
hls_opencv.h

template<int W>
void cvMat2AXIvideo(cv::Mat& cv_mat, hls::stream<ap_axiu<W,1,1,1> >& AXI_video_strm) {
    IplImage img = cv_mat;
    IplImage2AXIvideo<W>(&img, AXI_video_strm);
}

template<int W>
void AXIvideo2cvMat(hls::stream<ap_axiu<W,1,1,1> >& AXI_video_strm, cv::Mat& cv_mat) {
    IplImage img = cv_mat;
    AXIvideo2IplImage<W>(AXI_video_strm, &img);
}

++++++++++++++++++++++++++++++++++++++++++++++
hls_stream.h

template<typename __STREAM_T__>
class stream
{
	void operator >> (__STREAM_T__& rdata) {
        read(rdata);
    }

    void operator << (const __STREAM_T__& wdata) {
        write(wdata);
    }

	__STREAM_T__ read() {
        __STREAM_T__ elem;
        while(_data.empty())
          ;
          
        if (_data.empty()) {
            elem = __STREAM_T__();
        } else {
            elem = _data.front();
            _data.pop_front();
        }
        return elem;
    }

	void write(const __STREAM_T__& tail) { 
        _data.push_back(tail);
    }
}

+++++++++++++++++++++++++++++++++++++++++
hls_video.h

#include "hls/hls_axi_io.h"
#include "hls_math.h"
#include "hls_stream.h"

#include "utils/x_hls_utils.h"
#include "utils/x_hls_traits.h"
#include "utils/x_hls_defines.h"
#include "hls/hls_video_types.h"
#include "hls/hls_video_mem.h"
#include "hls/hls_video_core.h"
#include "hls/hls_video_imgbase.h"
#include "hls/hls_video_io.h"

#include "hls/hls_video_arithm.h"
#include "hls/hls_video_imgproc.h"
#include "hls/hls_video_histogram.h"
#include "hls/hls_video_fast.h"
#include "hls/hls_video_undistort.h"
#include "hls/hls_video_hough.h"
#include "hls/hls_video_harris.h"
#include "hls/hls_video_haar.h"
#include "hls/hls_video_stereobm.h"

++++++++++++++++++++++++++++++++++++++++++++++++++++
hls_video_io.h

namespace hls {
	...

} // namespace hls

//--------------------------------------------------------------------------
template<int W, int ROWS, int COLS, int T>
int AXIvideo2Mat(stream<ap_axiu<W,1,1,1> >& AXI_video_strm,
                 Mat<ROWS, COLS, T>& img)
{
    int res = 0;
    ap_axiu<W,1,1,1> axi;
    Scalar<HLS_MAT_CN(T), HLS_TNAME(T)> pix;
    int depth = HLS_TBITDEPTH(T);
    // std::cout << W << " " << depth << " " << HLS_MAT_CN(T) << "\n";
    assert(W >= depth*HLS_MAT_CN(T) && "Bit-Width of AXI stream must be greater than the total number of bits in a pixel");
    HLS_SIZE_T rows = img.rows;
    HLS_SIZE_T cols = img.cols;
    assert(rows <= ROWS);
    assert(cols <= COLS);
    bool sof = 0;
    
 loop_wait_for_start: while (!sof) {
#pragma HLS pipeline II=1
#pragma HLS loop_tripcount avg=0 max=0
        AXI_video_strm >> axi;
        sof = axi.user.to_int();
    }
    
 loop_height: for (HLS_SIZE_T i = 0; i < rows; i++) {
        bool eol = 0;
        
    loop_width: for (HLS_SIZE_T j = 0; j < cols; j++) {
#pragma HLS loop_flatten off
#pragma HLS pipeline II=1
            if (sof || eol) {
                sof = 0;
                eol = axi.last.to_int();
            } else {
                // If we didn't reach EOL, then read the next pixel
                AXI_video_strm >> axi;
                eol = axi.last.to_int();
                bool user = axi.user.to_int();
                if(user) {
                    res |= ERROR_IO_SOF_EARLY;
                }
            }
            
            if (eol && (j != cols-1)) {
                res |= ERROR_IO_EOL_EARLY;
            }
            
        loop_channels: for (HLS_CHANNEL_T k = 0; k < HLS_MAT_CN(T); k++) {
                AXIGetBitFields(axi, k*depth, depth, pix.val[k]);
            }
            
            img << pix;
        }
        
    loop_wait_for_eol: while (!eol) {
#pragma HLS pipeline II=1
#pragma HLS loop_tripcount avg=0 max=0
            // Keep reading until we get to EOL
            AXI_video_strm >> axi;
            eol = axi.last.to_int();
            res |= ERROR_IO_EOL_LATE;
        }
    }
    return res;
}


template<int W, int ROWS, int COLS, int T>
int Mat2AXIvideo(Mat<ROWS, COLS, T>& img,
                 stream<ap_axiu<W,1,1,1> >& AXI_video_strm)
{
    int res = 0;
    Scalar<HLS_MAT_CN(T), HLS_TNAME(T)> pix;
    ap_axiu<W,1,1,1> axi;
    int depth = HLS_TBITDEPTH(T);
    // std::cout << W << " " << depth << " " << HLS_MAT_CN(T) << "\n";
    assert(W >= depth*HLS_MAT_CN(T) && "Bit-Width of AXI stream must be greater than the total number of bits in a pixel");
    HLS_SIZE_T rows = img.rows;
    HLS_SIZE_T cols = img.cols;
    assert(rows <= ROWS);
    assert(cols <= COLS);
    bool sof = 1;
    
 loop_height: for (HLS_SIZE_T i = 0; i < rows; i++) {
 
    loop_width: for (HLS_SIZE_T j = 0; j < cols; j++) {
#pragma HLS loop_flatten off
#pragma HLS pipeline II=1

            if (sof) {
                axi.user = 1;
                sof = 0;
            } else {
                axi.user = 0;
            }
            
            if (j == (cols-1)) {
                axi.last = 1;
            } else {
                axi.last = 0;
            }
            
            img >> pix;
            axi.data = -1;
            
        loop_channels: for (HLS_CHANNEL_T k = 0; k < HLS_MAT_CN(T); k++) {
                AXISetBitFields(axi, k*depth, depth, pix.val[k]);
            }
            
            axi.keep = -1;
            AXI_video_strm << axi;
        }
    }
    return res;
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hls_video_mem.h

namespace hls {

/* Template class of Window */
template<int ROWS, int COLS, typename T>
class Window {
public:
    Window() {
#pragma HLS ARRAY_PARTITION variable=val dim=1 complete
#pragma HLS ARRAY_PARTITION variable=val dim=2 complete
    };

    /* Window main APIs */
    void shift_pixels_left();
    void shift_pixels_right();
    void shift_pixels_up();
    void shift_pixels_down();
    void insert_pixel(T value, int row, int col);
    void insert_row(T value[COLS], int row);
    void insert_top_row(T value[COLS]);
    void insert_bottom_row(T value[COLS]);
    void insert_col(T value[ROWS], int col);
    void insert_left_col(T value[ROWS]);
    void insert_right_col(T value[ROWS]);
    T& getval(int row, int col);
    T& operator ()(int row, int col);

    /* Back compatible APIs */
    void shift_left();
    void shift_right();
    void shift_up();
    void shift_down();
    void insert(T value, int row, int col);
    void insert_top(T value[COLS]);
    void insert_bottom(T value[COLS]);
    void insert_left(T value[ROWS]);
    void insert_right(T value[ROWS]);

    T val[ROWS][COLS];
    void restore_val();
    void window_print();
    T val_t[ROWS][COLS];
};
} // namespace hls
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值