Xilinx / xfopencv

Other
328 stars 143 forks source link

How can I do pixel-wise computation with a xf:Mat ? #30

Closed microlijun closed 5 years ago

microlijun commented 5 years ago

xf::Mat<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1> a; xf::Mat<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1> b; xf::Mat<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1> c; c(x,y)=a(x,y)/b(x,y) How can I get c by using xfOpenCv??? In OpenCv, I can directly do a/b, but xfOpenCv do not have pixel-wize division function. I tried to define a division function by myself. for (int i = 0; i < HEIGHT; i++) for (int j = 0; j < WIDTH; j++) { c[i][j] = a[i][j]/b[i][j]; } but I got error: '[]' could not be resolved So how can I do pixel-wise computation with a xf:Mat ? Could you give an example?

bgouthamb commented 5 years ago

@microlijun You need to use the '.data' pointer to access each pixel value of an xf::Mat object.

for (int i = 0; i < HEIGHT; i++){
     for (int j = 0; j < WIDTH; j++){
          c.data[i*WIDTH+j] = a.data[i*WIDTH+j] / b.data[i*WIDTH+j];
    }
 }

To know how to optimize the above implementation, have a look at anyone of the arithm functions.