How to access and use 1D matrix with OpenCV

时间:2018-01-23 19:17:05

标签: c++ opencv

I have a 1D array of size 12, that inside of each element has a 2D matrix. I want to pass as the input of a function the 1D array and inside of the function, in a cycle, I want to go through the array and access the values of the 2D matrix inside of the array. I am using separate headers.

In my main function, i define the array like:

cv::Mat kernels[12];
for(int n =0; n<12; n++){
    cv::Mat mat = cv::Mat::zeros(15, 15, CV_32S);
    kernels[x]=filtro.kernel(n,mat);
    x++;
    }

This for cycle adds values to the matrices.

Then I want to insert as input the 1D array in my correlate function, and I do so like this:

image_01_c=filtro.correlate(image_01_pad,kernels);

In my correlate function I define it like:

cv::Mat filter::correlate(cv::Mat& image_in, cv::Mat& kernels)

And then, when I want to use the 2D matrices, gives me this error:

correlate.cpp: In member function ‘cv::Mat filter::correlate(cv::Mat&,cv::Mat)’: correlate.cpp:41:23: error: no match for ‘operator[]’ (operand types are ‘cv::Mat’ and ‘int’  kernel_2d=kernels[i];

when I use it like this:

for (int i = 0; i < 12; i++){
    cv::Mat kernel_forca= cv::Mat::zeros(nlines,ncols,CV_32S);
    kernel_2d=kernels[i];
    cout<<"i:     "<< i << flush;

0 个答案:

没有答案