是否在mat中mat:Mat真的代表一个矩阵?

时间:2018-01-23 10:19:13

标签: fpga vivado vivado-hls

我正在研究Vivado HLS。我正在通过流阅读图像并将其存储在hls:mat中。我想对此mat执行按元素操作。垫真的代表一个矩阵吗?有没有办法像矩阵那样访问它,即A[rows][columns]

方法A.at<double>(0,0)无效。

2 个答案:

答案 0 :(得分:2)

不,根据Xilinx application note XAPP1167

  

第二个限制是用于建模的hls::Mat<>数据类型   图像在内部定义为像素流,使用   hls::stream<>数据类型,而不是外部像素数组   记忆。因此,图像不支持随机访问   cv::Mat<>.at()方法与cvGet2D()函数没有对应关系   可综合库中的等效函数。

因此,您只能将数据流式传输到hls::Mat或从import pandas as pd import numpy as np msft = pd.read_csv("week_51.csv") print(msft.head()) 传输数据,而您无法访问随机元素。

答案 1 :(得分:0)

我使用Sobel代码(XAP1167)找到答案

void created_window(MY_IMAGE& src, MY_IMAGE& dst, int rows, int cols)
{
  MY_BUFFER buff_A;
  MY_WINDOW WINDOW_3x3;

  for(int row = 0; row < rows+1; row++){
    for(int col = 0; col < cols+1; col++){
#pragma HLS loop_flatten off
#pragma HLS dependence variable=&buff_A false
#pragma HLS PIPELINE II = 1

      // Temp values are used to reduce the number of memory reads
      unsigned char temp;
      MY_PIXEL tempx;

      //Line Buffer fill
      if(col < cols){
          buff_A.shift_down(col);
          temp = buff_A.getval(0,col);
      }

      //There is an offset to accommodate the active pixel region
      //There are only MAX_WIDTH and MAX_HEIGHT valid pixels in the image
      if(col < cols && row < rows){
          MY_PIXEL new_pix;
          src >> new_pix;
          tempx = new_pix;
          buff_A.insert_bottom(tempx.val[0],col);
      }

      //Shift the processing window to make room for the new column
      WINDOW_3x3.shift_right();

      //The processing window only needs to store luminance values
      //rgb2y function computes the luminance from the color pixel
      if(col < cols){
          WINDOW_3x3.insert(buff_A.getval(2,col),2,0);
          WINDOW_3x3.insert(temp,1,0);
          WINDOW_3x3.insert(tempx.val[0],0,0);
      }
      MY_PIXEL conn_obj;


      //The operator only works on the inner part of the image
      //This design assumes there are no connected objects on the boundary of the image


          conn_obj = find_conn(&WINDOW_3x3);


      //The output image is offset from the input to account for the line buffer
      if(row > 0 && col > 0) {
          dst << conn_obj;
      }
    }
  }
}






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

#pragma HLS INTERFACE s_axilite port=rows bundle=CONTROL_BUS offset=0x14
#pragma HLS INTERFACE s_axilite port=cols bundle=CONTROL_BUS offset=0x1C
#pragma HLS INTERFACE s_axilite port=return bundle=CONTROL_BUS

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


    MY_IMAGE img_0(rows, cols);
    MY_IMAGE img_1(rows, cols);

#pragma HLS dataflow
    hls::AXIvideo2Mat(video_in, img_0);
    created_window(img_0, img_1, rows, cols);
    hls::Mat2AXIvideo(img_0, video_out);
}