如何将mat(OpenCV)转换为图像(JavaFX)? [英] How to convert mat(OpenCV) to image(JavaFX)?
本文介绍了如何将mat(OpenCV)转换为图像(JavaFX)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将mat(OpenCV)转换为图像(JavaFX)?
我认为这不是最好的方法:
How to convert mat(OpenCV) to image(JavaFX)? I think this isn't not best method:
MatOfByte byteMat = new MatOfByte();
Highgui.imencode(".bmp", mat, byteMat);
return new Image(new ByteArrayInputStream(byteMat.toArray()));
PS
Image - import javafx.scene.image.Image;
推荐答案
Paritosh,你方法的问题在于它只有它适用于类型为 CvType.CV_8U
或 CvType.CV_8S
的垫子,因为这些垫子可以包含在字节数组。如果Mat的类型是,假设 CvType.CV_32F
,则需要一个float数组来保存数据。 float数组不能被System.arraycopied到 byte [] targetPixels
数组中。
Paritosh, the issue with your method is that it only applies to the Mats with the type of CvType.CV_8U
or CvType.CV_8S
, since those Mats can be contained in a byte array. If the type of the Mat is, lets say, CvType.CV_32F
, you would need a float array to hold the data. The float array cannot be System.arraycopied into a byte[] targetPixels
array.
这篇关于如何将mat(OpenCV)转换为图像(JavaFX)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文