- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is there any alternative for OpenCV imshow() method in Java?
The HighGui class of the org.opencv.highgui package allows you to create and manipulate windows and display them. You can display an image in a window using the imshow() method of this class. This method accepts two parameters−
A string variable representing the name of the window.
A Mat object representing the contents of an image.
It is recommended to invoke the waitKey() method after imshow().
Example
The following example reads an image, converts it into a grayscale image, detects the edges in it and displays all the three images (original, gray-scale and, edges) in windows 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(); } }
Output
On executing, the above program generates three windows as shown below −
Original image −
Grayscale image −
Image with edges highlighted −
- Related Articles
- Is there any alternative solution for static constructor in java?
- Is there any alternative for CONCAT() in MySQL?
- Is there any method to convert a Set to immutable in Java
- Name two alternative arrangements for sewage disposal where there is no sewerage system.
- Is their any alternative to HTML5 iframe srcdoc?
- Is there any precautionary medicine available for Dengue?
- Which is the JavaScript RegExp to find any alternative text?
- Are there any ways to Manipulate Strings in Java.
- Is there any Python object inspector?
- Converting image to Grayscale without using any methods Java OpenCV.
- Is there any tool that can convert an XSD file to a Python class as JAXB does for Java?
- Working with MySQL WHERE.. OR query with multiple OR usage. Is there an alternative?
- Defining a discrete colormap for imshow in Matplotlib
- Is there is any mathematics table upto 30?
- Implement MySQL query using multiple OR statements. Any optimal alternative?

Advertisements