คุณสามารถคำนวณ bitwise exclusive หรือระหว่างสองภาพโดยใช้ bitwise_xor() วิธีการของ org.opencv.core.Core ชั้นเรียน
วิธีนี้ยอมรับ Mat สามแบบ ออบเจ็กต์ที่เป็นตัวแทนของเมทริกซ์ต้นทาง ปลายทาง และผลลัพธ์ จะคำนวณค่าบิตที่ไม่รวมหรือของแต่ละองค์ประกอบในเมทริกซ์ต้นทางและเก็บผลลัพธ์ไว้ในเมทริกซ์ปลายทาง
ตัวอย่าง
ในตัวอย่าง Java ต่อไปนี้ เรากำลังแปลงรูปภาพเป็นไบนารีและระดับสีเทา และคำนวณค่าบิตพิเศษหรือผลลัพธ์
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 {
//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, Imgcodecs.IMREAD_GRAYSCALE );
HighGui.imshow("Grayscale Image", src);
//Creating an empty matrix to store the results
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());
//Converting the gray scale image to binary image
Imgproc.threshold(src, threshold, 100, 255, Imgproc.THRESH_BINARY_INV);
HighGui.imshow("Binary Image", threshold);
//Applying bitwise Or operation
Core.bitwise_xor(src, threshold, dst);
HighGui.imshow("Bitwise XOR operation", dst);
HighGui.waitKey();
}
} ใส่รูปภาพ

ผลลัพธ์
ในการดำเนินการ โปรแกรมดังกล่าวจะสร้างหน้าต่างต่อไปนี้ -
ภาพมาตราส่วนสีเทา −

รูปภาพไบนารี −

Xor ระดับบิต −
