TomTom TomTom - 1 year ago 300
Java Question

Display OpenCV Mat with JavaFX

I would like to display

objects from OpenCV directly with JavaFX. I have seen that it is possible to convert a
object into a
. But as far as I know you can't display a
with JavaFX, so another conversion would have to take place.

Is there a way to directly convert it into a data structure that is displayable by JavaFX?

Answer Source

I have found a direct way to convert a Mat object to a JavaFX Image object.

MatOfByte byteMat = new MatOfByte();
Highgui.imencode(".bmp", mat, byteMat);
return new Image(new ByteArrayInputStream(byteMat.toArray()));

You can also encode it to .jpg but .bmp is faster.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download