Ask Your Question
1

Matrix Expression Comparison Operator

asked 2014-01-28 05:45:57 -0600

Adi gravatar image

The docs state (emphasis mine):

Comparison: A cmpop B, A cmpop alpha, alpha cmpop A, where cmpop is one of : >, >=, ==, !=, <=, <. The result of comparison is an 8-bit single channel mask whose elements are set to 255 (if the particular element or pair of elements satisfy the condition) or 0.

However, if img is CV_8UC3 and I write this:

cv::Mat res = img != 0; 
cout << res.channels() << endl;

This prints: 3

Based on the docs it seems that it should have printed 1.
Is this a bug in the docs or in the library?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-01-28 06:21:37 -0600

Nghia gravatar image

I'm leaning towards a wording bug in the doc because it makes sense to return 3 channels if your input is 3 channels.

Mat img = Mat(1,1,CV_8UC3);

img.at<Vec3b>(0)[0] = 0;
img.at<Vec3b>(0)[1] = 100;
img.at<Vec3b>(0)[2] = 200;

cout << (img != 0) << endl;

gives

[0, 255, 255]
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-01-28 05:45:57 -0600

Seen: 183 times

Last updated: Jan 28 '14