0

Previously, I use C API and now I'm migrating to C++ API opencv. Below are some of the thing that doen't go through. It says some kind of error of conditional expression in Mat. Using C API everything seems fine.

/// Initialize (C API)
vector<IplImage*> storeImg;

storeImg.pushback(...);

if( storeImg.at(i) == storeImg.at(0) )//no error

/// Initialize (C++ API)
vector<Mat> storeImg;

storeImg.pushback(...);

/// To use it
if( storeImg.at(i) == storeImg.at(0) )//error: conditional expression is illegal

Is there any other workaround for this?

Mzk
  • 1,102
  • 3
  • 17
  • 40

3 Answers3

0

You need to access the indices of storeImg like this

storeImg[i]

If you wish to then access elements of the Mat stored in the index, you can call

storeImg[i].at<float>(j)
Radford Parker
  • 731
  • 4
  • 14
  • if(storeImg[i] == storeImg[0]) still produce an error. Do you know why this is happening? – Mzk Feb 26 '13 at 08:22
  • If you do this: if(storeImg[i].data == storeImg[0].data), then you are just comparing the pointers to the data. If you want to make sure that the entire matrix is the same, then check here: http://stackoverflow.com/questions/9905093/how-to-check-whether-two-matrixes-are-identical-in-opencv – Radford Parker Feb 26 '13 at 15:03
0

I'm not sure about this but just tested and it works and verified by the way.

if(storeImg[i].data == storeImg[0].data)
Mzk
  • 1,102
  • 3
  • 17
  • 40
0

please clarify, what kind of comparison you intend.

if you got a vector<IplImage*> storeImg, ( storeImg[0]==storeImg[7] ) will compare the POINTERS only.

for a vector<Mat> storeImg the same expression would try to compare whole structs, which is in fact illegal.

did you want to check, if the CONTENT(pixels) is equal ?

that would be like: sum( storeImg[0] - storeImg[7] ) == 0

if you still want to compare pointers, ( storeImg[0].data == storeImg[7].data ) might work in the cv:Mat case, but it will fail, if you got clone()'s of other mats there

berak
  • 39,159
  • 9
  • 91
  • 89
  • I want to make sure that if storeImg[i] same as storeImg[0] then do something else do nothing. – Mzk Feb 27 '13 at 05:08