Bạn có thể tính toán kết hợp bitwise giữa hai hình ảnh bằng cách sử dụng bitwise_not () phương thức của org.opencv.core.Core lớp học.
Phương thức này chấp nhận hai Mat các đối tượng đại diện cho ma trận nguồn và đích, tính toán nghịch đảo của từng phần tử trong ma trận nguồn và lưu trữ kết quả trong ma trận đích.
Ví dụ
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(); } }
Hình ảnh đầu vào
Đầu ra
Khi thực thi, chương trình trên tạo các cửa sổ sau -