Phép XOR bitwise giữa hai ảnh dùng phương thức bitwise_xor() của lớp org.opencv.core.Core. Nhận 3 Mat (nguồn 1, nguồn 2, đích), tính XOR từng phần tử.
Ví dụ
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class BitwiseXORExample {
public static void main(String args[]) throws Exception {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
String file = "D://images//elephant.jpg";
Mat src = Imgcodecs.imread(file, Imgcodecs.IMREAD_GRAYSCALE);
HighGui.imshow("Grayscale Image", src);
Mat dst = new Mat(src.rows(), src.cols(), src.type());
Mat threshold = new Mat(src.rows(), src.cols(), src.type());
Mat gray = new Mat(src.rows(), src.cols(), src.type());
Imgproc.threshold(src, threshold, 100, 255, Imgproc.THRESH_BINARY_INV);
HighGui.imshow("Binary Image", threshold);
Core.bitwise_xor(src, threshold, dst);
HighGui.imshow("Bitwise XOR operation", dst);
HighGui.waitKey();
}
}
Ảnh gốc

Kết quả
Ảnh xám

Ảnh nhị phân

Bitwise XOR
