Displaying opencv mat using JavaFX

I want to display the mat object in opencv directly with JavaFX I've seen that the mat object can be converted to bufferedimage But as far as I know, you can't use JavaFX to display buffered image, so you have to do another conversion

Is there any way to convert it directly into a data structure that can be displayed by JavaFX?

Solution

I found a direct way to convert mat objects into JavaFX image objects

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

You can also code it as Jpg, but BMP is faster

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>