Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It seems that there isn't a function like imshow in the Java HighGUI package. But after a small search i found out that its possible to encode the image to a "BufferedImage" and then just load it into your GUI. So just load it like this: Mat image_tmp = your image

MatOfByte matOfByte = new MatOfByte();

Highgui.imencode(".jpg", image_tmp, matOfByte); 

byte[] byteArray = matOfByte.toArray();
BufferedImage bufImage = null;

try {

    InputStream in = new ByteArrayInputStream(byteArray);
    bufImage = ImageIO.read(in);
} catch (Exception e) {
    e.printStackTrace();
}

and then draw it like that:

g.drawImage(bufImage , 0, 0, null);

g in this examples is an instance of the class Graphics

Hopefully this is what you were searching for.

It seems that there isn't a function like imshow in the Java HighGUI package. But after a small search i found out that its possible to encode the image to a "BufferedImage" and then just load it into your GUI. So just load it like this: Mat image_tmp = your imagethis:

Mat image_tmp = your image
MatOfByte matOfByte = new MatOfByte();

Highgui.imencode(".jpg", image_tmp, matOfByte); 

byte[] byteArray = matOfByte.toArray();
BufferedImage bufImage = null;

try {

    InputStream in = new ByteArrayInputStream(byteArray);
    bufImage = ImageIO.read(in);
} catch (Exception e) {
    e.printStackTrace();
}

and then draw it like that:

g.drawImage(bufImage , 0, 0, null);

g in this examples is an instance of the class Graphics

Hopefully this is what you were searching for.