3

The below is my function prototype.

void devectorize(Mat &vec,Mat mask,Mat& img);

I am getting the below error when I try to call this function in my code. What would be the reason?

Mat V;

for(int i=0;i<V.cols;i++)
{
  devectorize(V.col(i),mask,E_img); //Error in this line
}
error: invalid initialization of non-const reference of type 'cv::Mat&' from an rvalue of type 'cv::Mat'
utils.h:11:6: error: in passing argument 1 of 'void devectorize(cv::Mat&, cv::Mat, cv::Mat&)'
LihO
  • 41,190
  • 11
  • 99
  • 167
user2727765
  • 616
  • 1
  • 12
  • 28

1 Answers1

4

You cannot bind a non-const reference to a temporary. In your case the first argument to devectorize is a non-const reference and the return value from V.col(i) is the temporary. This code would work

for (int i = 0; i < V.cols; i++)
{
    Mat tmp = V.col(i);
    devectorize(tmp, mask, E_img);
}

so would changing the first parameter of devectorize to const Mat&.

Vaughn Cato
  • 63,448
  • 5
  • 82
  • 132
john
  • 85,011
  • 4
  • 57
  • 81