Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Saving frames when frameRate%15 is not working

$
0
0

Hello there,

I have this code that saves a frame from the webcam everytime frameRate%15 ==0, and I only want 30 frames total.

Whit a frameRate of 60fps I should have 4 frames per second, but is not the case (it's not saving any frame) and i don't know why, any ideas?

I'm using Processing 2.2.1

import processing.video.*;
Capture cam;
int frames = 0;

void setup() {
  size(640, 480);
  String[] cameras = Capture.list();

  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
    cam = new Capture(this, cameras[1]);
    cam.start();
  }
  background(0);
}

void draw() {
  if (mousePressed) {
    if (cam.available() == true) {
      cam.read();
      image(cam, 0, 0);
      if (frameCount % 15 == 0) {
        saveFrame("frames/" + frames + ".png"); //voy guardando frames
        frames++;
      }
      if (frames > 29) {
        frames = 0;
      }
    }
  } else {
    background(0);
  }

  print("frame count: ");
  print(frameCount);
  print("  |  framerate: ");
  println(frameRate);
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles