Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Java

Phép toán Bitwise NOT trên hình ảnh OpenCV Java

Tính phép NOT bitwise trên ảnh bằng phương thức bitwise_not() của lớp org.opencv.core.Core.

Nhận 2 Mat (nguồn, đích), tính nghịch đảo từng phần tử nguồn và lưu vào đích.

Ví dụ minh họa

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 {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        
        String file = "D://images//elephant.jpg";
        Mat src = Imgcodecs.imread(file);
        HighGui.imshow("Original Image", src);
        
        Mat dst = new Mat(src.rows(), src.cols(), src.type());
        
        // Bitwise NOT
        Core.bitwise_not(src, dst);
        
        HighGui.imshow("Bitwise NOT operation", dst);
        HighGui.waitKey();
    }
}

Hình ảnh đầu vào và kết quả

Input: Phép toán Bitwise NOT trên hình ảnh OpenCV Java

Output: Phép toán Bitwise NOT trên hình ảnh OpenCV Java