Taking pictures every x seconds and overlaying

import processing.video.*;

Capture cam;

int nb_seconds, nb_images;
int nFrames = 10;

void setup() {
  size(600, 400);
  background(255);
  cam = new Capture(this, 640,480,30);
  cam.start();
  // draw() will execute 1 time per second
  frameRate(1);
}

void draw() {

  if(cam.available()){
    nb_seconds++;
    if (nb_seconds%3 == 0) {
      // this will execute every 3 seconds
      nb_images++;
      cam.read();
      PImage pg = cam.get();
      pg.save("image_" + nb_images + ".png");
      // tint the image in blue and add opacity
      // tint(red,green,blue,opacity)
      tint(0,0,255, 150);
      image(cam, 0,0);
    }
  }

}