将BufferedImage TYPE_INT_RGB转换为OpenCV Mat对象 [英] Convert BufferedImage TYPE_INT_RGB to OpenCV Mat Object

查看:505
本文介绍了将BufferedImage TYPE_INT_RGB转换为OpenCV Mat对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将BufferedImages存储在MySQL数据库中,并将它们检索到Java应用程序中.

I am storing BufferedImages inside a MySQL database and retrieve them to a java application.

BufferedImages类型为TYPE_INT_RGB.

The BufferedImages are of type TYPE_INT_RGB.

如何将图像转换为OpenCV Mat对象?

How can i convert that image to a OpenCV Mat object?

我总是得到一个

java.lang.UnsupportedOperationException: Mat data type is not compatible: 

例外.

有人可以帮忙吗?

推荐答案

自行解决.

    int[] data = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
    ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 4); 
    IntBuffer intBuffer = byteBuffer.asIntBuffer();
    intBuffer.put(data);

    Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3);
    mat.put(0, 0, byteBuffer.array());
    return mat;

图像是BufferedImage,您想要转换为Mat-Object.

image is the BufferedImage, you want to convert to a Mat-Object.

这篇关于将BufferedImage TYPE_INT_RGB转换为OpenCV Mat对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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