title: Node.js, OpenCV Trying to convert matrix to buffer with toBuffer() function
body: <p>I'm trying to convert openCv matrix using <code>toBuffer()</code>, it works fine with matrix that I create via <code>var mat = new cv.Matrix()</code>, but when I do the same with image opened via <code>cv.readImage</code>, toBuffer() returns nothing, here is my code:</p>
  
  <pre><code>var cv =require('opencv');
  var output;
  var mat = new cv.Matrix(90,90);
  cv.readImage("mona0.png", function(err,im){
    if (err) throw err;
    if (im.width() &lt; 1 || im.height() &lt; 1) throw new Error('Image has no size');
  
    im.bilateralFilter();
    console.log(im);
    output = im.clone();
    });
  var buff = mat.toBuffer();// it works and returns something like &lt;buffer ff d8 ff...&gt;
  //var buff = output.toBuffer(); // it doesn't work and returns nothing
  console.log(buff);
  </code></pre>
  
  <p>So, if it's possible, I would like to get output from <code>im</code> similar to output from <code>mat</code></p>
  
  <p>Thank you in advance.</p>
  
  <hr>
  
  <p>I tried the code you suggested, and it seems like after calling <code>.toBuffer</code> function it stops working, because resoult of <code>console.log('mat'+buff1)</code> doesn't show up <a href="https://i.stack.imgur.com/f6umW.png" rel="nofollow noreferrer">output</a>, so I found the way to convert something into the Buffer object (code is below), but in this way it converts the string '[Matrix 756*500]' not the contents of matrix, there is another tip which might be useful, if I'm trying to do  <code>var buff = new Buffer(output);</code>without converting to string it says, that <code>output</code> must be a string or array, so now I'm trying to convert <code>output</code> into array and there is a one more thing:  .toBufferAsync(), but it requires one argument, and I'm a bit confused which one.</p>
  
  <pre><code> var cv =require('opencv');
  var fs = require('fs');
  var mat = new cv.Matrix(90,90);
  cv.readImage("mona0.png", function(err,im){
    if (err) throw err;
    if (im.width() &lt; 1 || im.height() &lt; 1) throw new Error('Image has no size');
  
    im.bilateralFilter();
    console.log(im);
    var output = new cv.Matrix(im.width(),im.height())
    output = im.clone();
    var buff = new Buffer(output.toString('byte64')); // it should work now
    console.log('this is buff: ');
    console.log(buff);
    });
  var buff1 = new Buffer(mat.toString('byte64'));// it works and returns something like &lt;buffer ff d8 ff...&gt;
  console.log('this is buff1: ')
  console.log(buff1)
  </code></pre>