Ask Your Question

Revision history [back]

Operator overloads not working with vector

Hi All,

I have posted this on linuxquestion.org and have posted the link here. http://www.linuxquestions.org/questions/programming-9/opencv-error-4175591196/

For your convenience I'll place the contents here.

Hi All,

I have an OpenCV question. I'm not sure why this doesn't work with using vectors, but if I create a Mat variable it works. Does anyone have any thoughts on what I should do to fix this?

Code:

      vector<Mat> cv_dBuff_v;

... 
initialized with values
...

      // Works
      Mat tmpcv_dBuff0 = cv_dBuff_v[0];
      Mat tmpcv_dBuff1 = cv_dBuff_v[1];
      Mat tmpcv_dBuffnew = tmpcv_dBuff0 - tmpcv_dBuff1;


      // Does not work
      Mat tmpcv_dBuffnew2 = cv_dBuff_v[0] - cv_dBuff_v[1];

ERROR Message Code:

OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in arithm_op, file /path/opencv/opencv-2.4.13/modules/core/src/arithm.cpp, line 1287
terminate called after throwing an instance of 'cv::Exception'
  what():  /path/opencv/opencv-2.4.13/modules/core/src/arithm.cpp:1287: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function arithm_op

Resolution:

Hi All,

I figured out what the issue was. tmpcv_dBuff1 is of 0 size which means the vector that it came from is 0 size.

It turns out that there is some sort of operator load issue with opencv 2.4.9 when it comes to using them with a vector container. If I check the size to not do the math everything works. And with vectors it still attempts to use, which looks like to me as, unallocated references. And with declaring it as Mat tmpcv_dBuff1 on the stack it seems to know that it is 0 and not use it. Operators are doing something different in these corner cases and it shouldn't be.