Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Filling cv::Mat calling function row by row?

I have this method:

//codeSize previously defined
void generateRow(cv::Mat1f &row){
  if(row.cols != codeSize || !code.isContinous() || row.rows!=1)
    return;
  //fill row somehow
}

And I want to call it like this:

cv::Mat1f mat(rows,cols);
for(size_t i=0; i<rows; i++)
  generateRow(mat.row(i));

But I get this error message:

../EncoderManager.cpp:100:37: error: invalid initialization of non-const reference of type ‘cv::Mat1f& {aka cv::Mat_<float>&}’ from an rvalue of type ‘cv::Mat_<float>’

How can I solve this?

Filling cv::Mat calling function row by row?

I have this method:

//codeSize previously defined
void generateRow(cv::Mat1f &row){
  if(row.cols != codeSize || !code.isContinous() || row.rows!=1)
    return;
  //fill row somehow
}

And I want to call it like this:

cv::Mat1f mat(rows,cols);
for(size_t i=0; i<rows; i++)
  generateRow(mat.row(i));

But I get this error message:

../EncoderManager.cpp:100:37: error: invalid initialization of non-const reference of type ‘cv::Mat1f& {aka cv::Mat_<float>&}’ from an rvalue of type ‘cv::Mat_<float>’

How can I solve this?

Possible solution:

for(size_t i=0; i<rows; i++){
  cv::Mat1f row(1,cols);
  generateRow(row);
  row.row(1).copyTo(mat.row(i));
}

Is this the only solution? If so and if rows is big, this is going to be super inefficient!

Filling cv::Mat calling function row by row?

I have this method:

//codeSize previously defined
void generateRow(cv::Mat1f &row){
  if(row.cols != codeSize || !code.isContinous() || row.rows!=1)
    return;
  //fill row somehow
}

And I want to call it like this:

cv::Mat1f mat(rows,cols);
for(size_t i=0; i<rows; i++)
  generateRow(mat.row(i));

But I get this error message:

../EncoderManager.cpp:100:37: error: invalid initialization of non-const reference of type ‘cv::Mat1f& {aka cv::Mat_<float>&}’ from an rvalue of type ‘cv::Mat_<float>’

How can I solve this?

Possible solution:

for(size_t i=0; i<rows; i++){
  cv::Mat1f row(1,cols);
  generateRow(row);
  row.row(1).copyTo(mat.row(i));
}

Is this the only solution? If so and if rows is big, this is going to be super inefficient!