-2

I encountered the following while trying to convert some C++ code that uses OpenCV to Java. I'd like to know what the ~ operator does to the Mat object gradient_grown in the following code and what's the Java equivalent to this?

Mat edge_enhanced_mser      = ~gradient_grown & mser_mask;

1 Answers1

3

It is the equivalent of the bitwise NOT operator overloaded for the Mat class. In this case, it will invert all bits in the matrix. It is listed in the section Matrix Expressions in the documentation:

Bitwise logical operations: A logicop B, A logicop s, s logicop A, ~A, where logicop is one of : &, |, ^.

In Java, you can use the bitwise_not() method:

bitwise_not

public static void bitwise_not(Mat src, Mat dst)

Inverts every bit of an array.

Note you need a new Mat to store the result:

bitwise_not(gradient_grown, gradient_grown_complement);
Community
  • 1
  • 1
Anderson Vieira
  • 8,919
  • 2
  • 37
  • 48