How to create Mat from byte [] using JavaCV

Trying to use JavaCV for image processing to rotate an image according to its Exif data. Reading and writing from a file in a Mat or IplImage works, but since the file is being loaded or loaded, I also want to be able to do the same thing as handling the byte [], instead of writing to the file.

However, I cannot find how to instantiate Mat from byte []. The method 'aMat.put (0, 0, byteArray)' that is mentioned in some of the answers is not available in the Mat instance in javacp version 1.0 using javacpp-presets: opencv: 3.0.0.

Attempting to put bytes into Mat data via: 'aMat.data (). put (imageBytes, 0, 0) 'throws NPE because data () returns null. I cannot find how to set the data as this is a JNI call.

Any idea on how to create opencv_core.Mat from bytes []?

+3


source to share


1 answer


Have you tried using:

yourMat.data().put(yourByteArray);

      



Just make sure yourMat

it's the right size.

+2


source







All Articles