Ask Your Question

Filling cv::Mat calling function row by row?

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

lovaj gravatar image

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

I have this method:

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

And I want to call it like this:

cv::Mat1f mat(rows,cols);
for(size_t i=0; i<rows; 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);

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

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

berak gravatar image
edit flag offensive delete link more


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

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

Question Tools

1 follower


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

Seen: 393 times

Last updated: Jan 21 '17