The
HighGui class of the org.opencv.highgui package allows you to create and manipulate windows and display them. You can use the imshow() method of this class to display an image in a window. This method accepts two parameters -
A string variable representing the name of the window.
Mat object representing the image content.
It is recommended to call the waitKey() method after imshow().
The following The example reads an image, converts it to grayscale, detects edges in it and displays all three images (original, grayscale and edges) in a window using HighGui.
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[]) { //Loading the OpenCV core library System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //Reading the Image from the file Mat src = Imgcodecs.imread("D://images//window.jpg"); HighGui.imshow("Original Image", src); //Converting color to gray scale Mat gray = new Mat(src.rows(), src.cols(), src.type()); Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGB2GRAY); HighGui.imshow("Gray Scale Image", gray); //Applying canny Mat dst = new Mat(src.rows(), src.cols(), src.type()); Imgproc.Canny(gray, dst, 100, 100*3); HighGui.imshow("Edges", dst); HighGui.waitKey(); } }
When executed, the above program generates three windows, as shown below-
Original image-
Grayscale image-
Edge Highlighted Image-
The above is the detailed content of Is there an alternative to OpenCV imshow() method in Java?. For more information, please follow other related articles on the PHP Chinese website!