lmx719
lmx719

Reputation: 31

opencv find index of members in Mat which are greater than zero

I have a cv::Mat, and I want to get the index of members which are greater than zero on the front several columns. In case I am not clear, I want to give an example:

double data[8] = {0.7, -0.1, 0.2, 0.4, 0.8, 0.7, -0.6, 0.3}
Mat example(2, 4, CV_64F, data);

The index of members greater than zero is:

index = {1 0 1 1 
         1 1 0 1}

And I want to get the first three columns of index:

final = {1 0 1 
         1 1 0}

Is there functions in OpenCV that I can use to solve this problem?

Thank you very much.

Upvotes: 0

Views: 2648

Answers (1)

Michael Burdinov
Michael Burdinov

Reputation: 4448

Yes you can do this in very simple way:

Mat index;
threshold(example, index, 0, 1, THRESH_BINARY);
Mat final = index(Rect(0,0,3,2));
// display result
cout << final << endl;

See documentation of threshold function.

Upvotes: 1

Related Questions