使用JavaFX显示OpenCV Mat [英] Display OpenCV Mat with JavaFX

查看:73
本文介绍了使用JavaFX显示OpenCV Mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想直接用JavaFX显示来自OpenCV的Mat对象.我已经看到可以将Mat对象转换为BufferedImage.但是据我所知,JavaFX无法显示BufferedImage,因此必须进行另一次转换.

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

是否可以直接 将其转换为JavaFX可显示的数据结构?

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

推荐答案

我发现了将Mat对象转换为JavaFX Image对象的直接方法.

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()));

您也可以将其编码为.jpg,但.bmp更快.

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

这篇关于使用JavaFX显示OpenCV Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆