Romantic Electron Romantic Electron -5 years ago 184
Java Question

What is ~ operator in opencv , C++?

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
in the following code and what's the Java equivalent to this?

Mat edge_enhanced_mser = ~gradient_grown & mser_mask;

Answer Source

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:


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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download