0

I'm trying to get the ImageData without using canvas. I will be passing the image data into tensorflow poseEstimation hence I don't want to display it on the screen.

I've tried to create an in-memory canvas according to this stackoverflow post but can't seem to get it to work.

  const data = ffmpeg.FS("readFile", "file_1.png");
  // data = Uint8Array

  const canvas = document.createElement("canvas");
  const context = canvas.getContext("2d");
  context.drawImage(data, 0, 0);
  const myData = context.getImageData(0, 0);

  console.log("myData", myData);
  • The ffmpeg.FS("readfile",... ) call will only return the png image's binary data, not the pixel data. You need to use a png decoder for this. – Kaiido Aug 23 '21 at 05:34
  • I don't fully understand the ffmpeg API, but I'd think it's very likely that there's a callback or a promise that needs to be resolved to make sure the image data is fully loaded and rendered before `context.drawImage(data, 0, 0)` is executed. – kshetline Aug 23 '21 at 05:43

0 Answers0