ejb1004
ejb1004

Reputation: 21

Webcam footage stopping when mouseClicked to take an image of video

I'm learning about image processing in class and I need to be able to take a screenshot of the webcam video that I'm displaying to the screen currently using p5.js. The problem is when I click the mouse to take the image, the webcam video stops/freezes on the frame when I clicked the mouse to take the image. I'm not sure what the problem is/how to keep the webcam video live after I have taken the picture. Thank you!

let video;
let img;

function setup()
{
  createCanvas(900,600);
  pixelDensity(1);
  video = createCapture(VIDEO);
  video.hide(); //hidden default video showing
}

function draw()
{
  background(255);

  imageMode(CENTER);
  translate(width/2, height/2);
  scale(-1,1,1); //flip image to be correct orienation 
  image(video, 0,0, 160, 120);
}


function saveImage()
{
  img = video.get()
  save(img, 'myPic.png');
}

function mousePressed()
{
  saveImage();
}

Upvotes: 0

Views: 37

Answers (0)

Related Questions