0

segment returns segmentation map(segment.segmentationMap) as Uint8ClampedArray,I want to render this on my canvas so I send segment in visualise function :

 const segment =  await model.segment(video)
    const context = canvasref.current.getContext("2d");
    requestAnimationFrame(()=>{visualise(segment, context)});

But I always get error ctx.canvas.width is zero always and height also

export const visualise = (output, context) => {

var image = new ImageData(output.segmentationMap, ctx.canvas.width, ctx.canvas.height);
    ctx.drawImage(image,0,0)

}
aryanknp
  • 1,135
  • 2
  • 8
  • 21
  • 3
    You have to specify the canvas width and height *on* the canvas tag, not as a CSS style attribute. See [this](https://stackoverflow.com/questions/4938346/canvas-width-and-height-in-html5). – user11350388 Jan 17 '21 at 08:02
  • @user11350388 thanks you are correct but I have to use output.width and output.height as then width and height were not matching the attribute of uint8array (width*height*4) – aryanknp Jan 17 '21 at 10:36
  • Could you show the error you have ? – edkeveked Jan 20 '21 at 21:14

0 Answers0