I am storing BufferedImages inside a MySQL database and retrieve them to a java application.
The BufferedImages are of type TYPE_INT_RGB.
How can i convert that image to a OpenCV Mat object?
I do always get a
java.lang.UnsupportedOperationException: Mat data type is not compatible:
Exception.
Can somebody help?
解决方案
Got it on my own.
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;
image is the BufferedImage, you want to convert to a Mat-Object.