Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Mat (comparison) operators documentation

Do you know where one could find documentation for cv::Mat operators, like <, <= etc? My current doubt is to know if the < operator returns ones or ~0 values (=255 for a uint8_t image, =65535 for a uint16_t image and so on). Reading here, it is implied that the expected behaviour is the one given by the equivalent compare call. But I struggle to find a reference in the OpenCV documentation.

I tried to google:

opencv mat operator documentation

like image 330
Antonio Avatar asked May 04 '15 12:05

Antonio


1 Answers

The right search term was Matrix Epressions.

From OpenCV 2 Documentation:

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.

In OpenCV 3 the documentation about Matrix Expressions is scattered in the page Operations on arrays. There is a collection of Matrix Expression here, but with empty documentation! In particular to know what the < operator does, one has to check the documentation of cv::compare:

When the comparison result is true, the corresponding element of output array is set to 255. The comparison operations can be replaced with the equivalent matrix expressions:

Mat dst1 = src1 >= src2; 
Mat dst2 = src1 < 8;
...
like image 107
Antonio Avatar answered Nov 13 '22 10:11

Antonio