saveFrame() to screencap processed video

edited November 2015 in Questions about Code

I've written a program to process a webcam with a Luma key. For some reason saveFrame() only saves the original video from the Webcam, instead of the processed video. How can I fix this?

import processing.video.*;
Capture cam;

void setup() {
  fullScreen();
  frameRate(5);
  String[] cameras = Capture.list();
  background(0);

  cam = new Capture(this, cameras[0]);
  cam.start();
}


void draw() {
  if (cam.available() == true) {
    cam.read();
  }

  image(cam, 0, 0, width, height);
  loadPixels();
  for (int loc = 1; loc < pixels.length; loc++) {
    float r = red(pixels[loc]);
    float g = green(pixels[loc]);
    float b = blue(pixels[loc]);
    float preAlpha = (r+g+b)/3;
    if (preAlpha < 70) {
      preAlpha = 0;
    }
    float alpha = preAlpha/5;
    pixels[loc] = color(r, g, b, alpha);
  }

  updatePixels();
}

void mousePressed() {
  saveFrame();
}

Answers

  • https://processing.org/reference/mousePressed_.html

    The mousePressed() function is called once after every time a mouse button is pressed.

    Try to use the boolean vatiable to start the record.

    boolean startRec = false;
    
    void draw() {
      if(startRec ) {
        saveFrame();
      }
    }
    
    void mousePressed() {
      startRec = !startRec;
    }
    
  • I only want saveframe to occur once, the problem is that it is saving the original video, not the processed video

  • edited November 2015
    // forum.processing.org/two/discussion/13533/saveframe-to-screencap-processed-video
    // 2015-Nov-17
    
    boolean shotFrame;
    
    void draw() {
      if (shotFrame) {
        saveFrame("####.jpg");
        shotFrame = false;
      }
    
     image(cam, 0, 0, width, height);
     // ...
    }
    
    void mousePressed() {
      shotFrame = true;
    }
    
  • It still isn't capturing the final image, just the input from the camera

  • Move the lines 7-10 of gotoloops code to the bottom of draw()

  • Still isn't fixing it, I can show an example of what I mean when I get home

  • Ok so I utilized PGraphics and now it works!

Sign In or Register to comment.