如何使用 Java OpenCV 在图像上执行按位取反操作?
你可以使用 org.opencv.core.Core 类的 bitwise_not() 方法在两幅图像之间计算按位与运算。
此方法接受两个 Mat 对象,表示源矩阵和目标矩阵,计算源矩阵中每个元素的逆,并将结果存储在目标矩阵中。
示例
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
public class BitwiseNOTExample {
public static void main(String args[]) throws Exception {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//Reading the Image
String file ="D://images//elephant.jpg";
Mat src = Imgcodecs.imread(file);
HighGui.imshow("Grayscale Image", src);
//Creating an empty matrix to store the result
Mat dst = new Mat(src.rows(), src.cols(), src.type());
//Applying bitwise not operation
Core.bitwise_not(src, dst);
HighGui.imshow("Bitwise NOT operation", dst);
HighGui.waitKey();
}
}输入图像

输出
执行后,以上程序将生成以下窗口 -

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP