I want to store a descriptor matrix generated by a random OpenCV descriptor extractor as a database entity.
Assuming desc is the descriptor Matrix
String s = (desc.reshape(1,1)).dump;
To get the matrix back from the database, I did
Mat desc = new Mat(numberOfRows * numberOfCols * numberOfChannels, 1, type);
/* I stored number of rows and number of cols and type of the matrix separately and pass them to the function that returns the matrix */
String ss[] = s.substring(1, s.length -1).split(", ");
int[] temp = new int[sss.length ];
for(int i = 0; i < sss.length; i++) temp [i] = Integer.parseInt(sss[i]);
MatOfInt int_values = new MatOfInt(temp);
int_values.convertTo(desc, type);
desc = fingerprint.desc(numberOfChannels, numberOfRows);
This works fine but takes a lot of time, especially the .split method and the loop involving parseInt due to the large number of elements in the matrix (about 100k in my case).
My question is: is there a better way to do this?
my second question is, come on, assigning a 100K long string array and parsing it (given the fact that the strings are actually 2-3 characters at most) shouldn't really take 2 seconds, is it because Android/Java is slow
OpenCV provides
FileStorage
class for persistence as in link. Basically theMat
image could be saved as XML/YAML file from which we could read later. A simple example will be as below.But we don't have
FileStorage
java wrapper in Android. Alternative could be invoking above code over JNI as in this example or even better - check Berak's sample.