1

I have this matlab code ,where i tried to find the 'j' in matrix color.I cant find a usefull function in opencv which can do the same job like matlab find do.i have tried some iterative method with 3 for loops ,but that were too cumbersome,Can you guys help me out?

if (find(Colorr==j))
    tt=tt+1;
    test=[test;ColorValues(:,j,1),ColorValues(:,j,2),ColorValues(:,j,3)];
end

this is the code i have written to covert to opencv

for(j=0;j<ColorValues.cols/2;j++)
    for(i=0;i<Color.cols;i++){
        if(j=input[Color.step*i+1]){
            tt++;
            for(k=0;k<ColorValues.rows;k++){

            }
        }

    }
Ishant Mrinal
  • 4,898
  • 3
  • 29
  • 47

1 Answers1

3

Assuming Color is a properly initialized single-channel cv::Mat, you can use the combination of overloaded operator== and cv::countNonZero() to do what you wish. operator== returns a mask where each element is one if the value in Color matches j, or zero otherwise.

if(cv::countNonZero(Color == j))
{
   // Do something...
}
Aurelius
  • 11,111
  • 3
  • 52
  • 69