title: Best way to convert an opencv matrix to string for storage in database in Android (Java)
body: <p>I want to store a descriptor matrix generated by a random OpenCV descriptor extractor as a database entity. </p>
  
  <p>Assuming desc is the descriptor Matrix </p>
  
  <pre><code>String s = (desc.reshape(1,1)).dump;
  </code></pre>
  
  <p>To get the matrix back from the database, I did </p>
  
  <pre><code>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 &lt; 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);
  </code></pre>
  
  <p>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).</p>
  
  <p>My question is: is there a better way to do this? </p>
  
  <p>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</p>