My C++ server sends a video stream from a computer's usb to a Java client.
In order to send an image(Mat object) from C++ I'm using FileStorage class to store the image in a string:
cv::FileStorage fs(".xml", cv::FileStorage::WRITE + cv::FileStorage::MEMORY);
fs << "mymatrix" << frame;
string buff = fs.releaseAndGetString(); //buff has all the Mat object info.
The client receives buff ,creates XML file and reads it using : Java: How to read and write xml files?
The image datatype is "3u" (=CV_8UC3), so I created a byte array to store the matrix data:
//data is a string that contains the matrix data
byte[] Bdata = data.getBytes();
and used this code to create the Mat object ( taken from https://groups.google.com/forum/#!topic/android-opencv/QEwhgO88ZwM ):
//Irows = number of rows
//Icols = number of columns
Mat mat = new Mat(Irows,Icols,CvType.CV_8UC3);
mat.put(0,0,Bdata);
but "mat.put.." is generating this error:
Exception in thread "main" java.lang.UnsupportedOperationException: Provided data element number (3742097) should be multiple of the Mat channels count (3)
I don't understand what is the problem with the byte array?
Any idea would be appreciated.
Edit : Though I'm not near my computer, so I can't confirm this, it appears that the large number in the error is the length of the array and it doesn't divide by 3 - the number of channels. I've no idea why.