Ask Your Question
0

Operator overloads not working with vector

asked 2016-10-13 11:06:59 -0600

Hi All,

I have posted this on linuxquestion.org and have posted the link here. http://www.linuxquestions.org/questio...

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.

edit retag flag offensive close merge delete

Comments

Is this a bug that needs a ticket for opencv?

gothrog gravatar imagegothrog ( 2016-10-13 11:07:43 -0600 )edit

i do not think so, atm.

can you try to improve your example code, so folks here can try to reproduce it ?

berak gravatar imageberak ( 2016-10-13 23:35:00 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-04 13:30:20 -0600

Hi Berak,

Here is the portion of code that needed to be adapted to work around this issue. I had to not do the operation if it is empty. Hope it helps.

     const int buffSize[] = { numCols, numRows };
     Mat tmpcv_dBuffnew = Mat::zeros(2, buffSize, CV_32FC1);
     //Mat tmpcv_dBuffnew = tmpcv_dBuff0 - tmpcv_dBuffX;

     // if the buffer is not empty add it to the equation for use
     // OpenCV seems to have a bug in the operator overloads.  Doesn't use vectors correctly with the overload
     // Check for semi initialized values that are 0, still won't work when 0.
     if ( !cv_dBuff_v[X].empty() && 0 != cv_dBuff_v[X].at<double>(0,0) )
     {
        tmpcv_dBuffnew = cv_dBuff_v[0] - cv_dBuff_v[X];
     }
     else
     {
        if (DEBUG)
        {
           cout << "x~~~~~~~~~~dBuff_X is empty~~~~~~~~~~~~" << endl;
        }
        tmpcv_dBuffnew = cv_dBuff_v[0];
     }
edit flag offensive delete link more

Comments

  • this is not an "answer" at all. (better remove it, edit your original question, and put it there)
  • there will be no successful help, unless folks can actually try your code, which means: try to come up with a minimal, self-consistant example, that highlights your problem. as of now - no.
berak gravatar imageberak ( 2016-11-04 13:40:05 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-10-13 11:06:59 -0600

Seen: 384 times

Last updated: Nov 04 '16