Lớp HighGui trong gói org.opencv.highgui cho phép tạo và thao tác cửa sổ hiển thị. Hiển thị ảnh trong cửa sổ bằng phương thức imshow() nhận 2 tham số:
- String: tên cửa sổ.
- Mat: nội dung ảnh.
Khuyến nghị gọi waitKey() sau imshow().
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;
import org.opencv.imgproc.Imgproc;
public class ImshowExample {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat src = Imgcodecs.imread("D://images//window.jpg");
HighGui.imshow("Original Image", src);
// Chuyển xám
Mat gray = new Mat(src.rows(), src.cols(), src.type());
Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGB2GRAY);
HighGui.imshow("Gray Scale Image", gray);
// Canny edge
Mat dst = new Mat(src.rows(), src.cols(), src.type());
Imgproc.Canny(gray, dst, 100, 100*3);
HighGui.imshow("Edges", dst);
HighGui.waitKey();
}
}
Kết quả
Ảnh gốc: 
Ảnh xám: 
Ảnh cạnh: 