OpenCV throws exception when calling Mat.put() with direct bytebuffer
Hello,
I'm getting this java exception in my code using OpenCV SDK for Android :
07-25 09:05:32.258 4431 5373 E ContentValues: byte buffer size = 1228800 07-05 09:03:13.859 7043 7117 E AndroidRuntime: java.lang.UnsupportedOperationException: Provided data element number (1228807) should be multiple of the Mat channels count (3) 07-05 09:03:13.859 7043 7117 E AndroidRuntime: at org.opencv.core.Mat.put(Mat.java:1011)
Mat srcIrImage = new Mat(width * 2,height * 2, CV_8UC3);
srcIrImage.put(0,0, buffer.array()); ==> throws the exception
buffer is a direct byte buffer allocated this way:
buffer = ByteBuffer.allocateDirect(previewRGBAArraySize).order(ByteOrder.LITTLE_ENDIAN);
When using ByteBuffer.allocate it will work but I have a constraint to use direct byte buffers.
May be OpenCV doesn't handle Little-endian as it should. What OpenCV calls data element number 1228807 seems to be the capacity of the buffer. This size is of 1228800 when not using direct buffers. Why is there a difference of 7 bytes here? It seems that OpenCV lib appends these 7 bytes.