Display Image OpenCV Java

Basic reading image from java

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
//Load native library
//Mat object used to host the image
Mat imageArray;
//Read image file from vile system

If you want to view images you can not use imshow because OpenCV-java does not have this method either. Instead, you can write the following method.

private static BufferedImage ConvertMat2Image(Mat imgContainer{
    MatOfByte byteMatData = new MatOfByte();
    //image formatting
    Imgcodecs.imencode(".jpg", imgContainer,byteMatData);
    // Convert to array
    byte[] byteArray = byteMatData.toArray();
    BufferedImage img= null;
    try {
        InputStream in = new ByteArrayInputStream(byteArray);
        //load image
        img= = ImageIO.read(in);
    } catch (Exception e) {
        return null;
    return img;

You can view the result object in the Jframe, Jlabel (jlabel icon) etc.

if you want to reproduce, please indicate the source:
Display Image OpenCV Java - CodeDay