Mat<> OpenCV 3中的BufferedImage转换

时间:2016-11-04 11:25:15

标签: java opencv javacv

显然,在带有Java绑定的OpenCV 2.4中,可以将Mat转换为BufferedImage

val greyMat = new Mat()
opencv_imgproc.cvtColor(mat, greyMat, opencv_imgproc.CV_BGR2GRAY, 1)
ImageIO.write(greyMat.getBufferedImage, "jpg", new File("output_grey.jpg"))

我尝试更新使用此代码的项目(并且它已经工作,我检查过)使用OpenCV 3.1,看起来这个方法已经消失了。

为什么这个方法getBufferedImage已从API中删除,我该如何回复它?

1 个答案:

答案 0 :(得分:0)

现在似乎有一个单独的转换器类:Java2DFrameConverter

import org.bytedeco.javacv.Java2DFrameConverter

val greyMat = new Mat()
val conv = new Java2DFrameConverter
opencv_imgproc.cvtColor(mat, greyMat, opencv_imgproc.CV_BGR2GRAY, 1)
ImageIO.write(conv.getBufferedImage(greyMat), "jpg", new File("output_grey.jpg"))