Home > Java > javaTutorial > Is there an alternative to OpenCV imshow() method in Java?

Is there an alternative to OpenCV imshow() method in Java?

WBOY
Release: 2023-08-27 22:33:01
forward
804 people have browsed it

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().

Example

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();
   }
}
Copy after login

Output

When executed, the above program generates three windows, as shown below-

Original image-

在Java中是否有OpenCV imshow()方法的替代方案?

Grayscale image-

在Java中是否有OpenCV imshow()方法的替代方案?

Edge Highlighted Image-

在Java中是否有OpenCV imshow()方法的替代方案?

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template