How to compare scalars in OpenCV

E_learner picture E_learner · Oct 3, 2012 · Viewed 7.5k times · Source

I have a class called "myClass", which returns "cv::Scalar" type, and I want to do this:

cv::Scalar myValue; 
for ( myValue > myClass (i,j) )
.... 

But the comparison part in the "for" line gives out error, saying "no operator > matches these operands". Could someone help me? Thank you.

Answer

Jav_Rock picture Jav_Rock · Oct 3, 2012

In order to complete Zhi Lu's answer:

If you want to compare an element of Scalar, you should do next:

cv::Scalar scalar(myValue);   //here you assign a value to the element (0,0)
for (scalar.val[0,0] > myClass (i,j)) // access the elment of Scalar
{
}

Anyway there is no point on using Scalar if you just want a single value. And also note that you need a proper for loop expression like

for(i = 0; i < 0; i++){}