2

I currently have a program running that sends an OpenCV to my Node server by sending the matrix values along with the number of rows and columns. I want to base64 encode this image on the Node server so I can view the image on the front end. I tried doing a .toString('base64') on the matrices values but this didnt work. My question is related to this question OpenCV cv::Mat to std::ifstream for base64 encoding but instead of doing this in C++ Id like to do it on Node.
Heres what the matrices values look like when comma separated. enter image description here

Community
  • 1
  • 1
Daniel Kobe
  • 9,376
  • 15
  • 62
  • 109
  • 1
    possible duplicate of [How to do Base64 encoding in node.js?](http://stackoverflow.com/questions/6182315/how-to-do-base64-encoding-in-node-js) – BeyelerStudios Aug 21 '15 at 14:33
  • As mentioned I attempted this method, Im not sure the mat image can be directly encoded to base64 – Daniel Kobe Aug 21 '15 at 14:36

1 Answers1

0

This should do the trick.

const outBase64 =  cv.imencode('.jpg', outputImage).toString('base64');
const output = 'data:image/jpeg;base64,' + outBase64;
return output;

Obviously depending on your image format you might need to change the encoding.

timo
  • 11
  • 1