คุณสามารถคำนวณการเชื่อมโยงระดับบิตระหว่างสองภาพโดยใช้ bitwise_and() วิธีการของ 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 BitwiseAndExample {
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 and operation
Core.bitwise_and(src, threshold, dst);
HighGui.imshow("Bitwise And operation", dst);
HighGui.waitKey();
}
} ใส่รูปภาพ

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

ภาพไบนารี −

ระดับบิตและ −
