Skip to content

base 64 image - backend #105

Answered by vladmandic
juancruzsosagab asked this question in Q&A
Discussion options

You must be logged in to vote

something like this?

const tf = require('@tensorflow/tfjs-node');
function b64toTensor(b64string) {
  const img = Buffer.from(b64string, 'base64');
  const hcw = tf['node'].decodeJpeg(img); // decode jpeg data (or use different methods for png, gif, etc.) to tensor in hcw format
  const nhcw = hcw.expandDims(0); // expand hcw to nhcw that can be directly used by faceapi
  tf.dispose(hcw);
  return nhcw; // dont forget to dispose tensor once faceapi is done
}

alternatively, you can use node-canvas with the same img variable and then pass canvas object to faceapi
for example:

function b64toCanvas(b64string) {
  const img = Buffer.from(b64string, 'base64');
  const input = await canvas.loadI…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@juancruzsosagab
Comment options

Answer selected by vladmandic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants