Display image using Mat in OpenCV Java

pupilx picture pupilx · Oct 22, 2014 · Viewed 14.7k times · Source

I am writing my first program in OpenCV in Java and I'd like to ask, is it possible to load and display image from file only using Mat? I found solution on this website http://answers.opencv.org/question/31505/how-load-and-display-images-with-java-using-opencv/ but it changes Mat to Image before. I'll be grateful for any tips

Answer

Milorenus Lomaliza picture Milorenus Lomaliza · Jan 23, 2020

This is an old question but for those who still face the same problem there is an implementation of "imshow" now in OpenCV for Java (I am using verion 4.1.1) under HighGui static object.
So you would first import it like:

import org.opencv.highgui.HighGui;

and then display the image like:

HighGui.imshow("Image", frame);
HighGui.waitKey();

Where 'frame' is your OpenCV mat object.