Ask Your Question

Revision history [back]

Filling out elements of a cv::Mat manually

Hello everyone. I need to be able to set all the values of a matrix manually. I tried used the .at member of the Mat class but it always segfaults.

here is what I want to do

Mat test;
    test=Mat::zeros(Img.rows, Img.cols, CV_32FC2);


    for( int y = 0; y < Img.rows; y++ )
    {
      for( int x = 0; x < Img.cols; x++ )
      {
         if (some conditions are met)
          test[y][x][channel 1] = OtherMatrix[y][x];
         else
          test[y][x][channel 2] = OtherMatrix[y][x];              

      }

    }

Get it? depending on those conditions, I want to fill the different channels of test with values from another matrix already calculated.

Thanks in advance!