Ask Your Question
0

Filling cv::Mat calling function row by row?

asked 2017-01-21 04:48:14 -0600

lovaj gravatar image

updated 2017-01-21 05:02:47 -0600

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!

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2017-01-21 04:54:54 -0600

berak gravatar image
edit flag offensive delete link more

Comments

@berak Thanks for your answer. Please give a look at my Possible solution.

lovaj gravatar imagelovaj ( 2017-01-21 05:02:29 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-21 04:48:14 -0600

Seen: 446 times

Last updated: Jan 21 '17