How to add a simple tint() effect to a video stream?

edited December 2014 in How To...

Hi Processing Forums.

I've recreated a problem I'm experiencing in a more complex, long and messy code I have.

I need to add a "filter" to the image I'm receiving from my camera, and export the processed image as jpg. I'm using PGraphics in the following code. I've been using a big PImage[] array, with no success.

// Some sample code for exporting a filtered jpg out of a live stream

import processing.video.*;
Capture cam;

PGraphics pg;

void setup() {

  size(640, 480);
  pg = createGraphics(width, height);
  cam = new Capture(this, width, height, "/dev/video0");
  cam.start();
}

void draw() {

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

  image(cam, 0, 0, width, height);
}

void keyPressed() {
  switch (key) {
  case ' ': // ADD FRAME
    filterBlue();
    break;
  
   case 'm': // ADD FRAME
    filterRed();
    break;
  }
}


void filterBlue(){
     tint(0, 0, 255);
     pg.image(cam, 0, 0, width, height); 
     pg.save("blue.jpg");
}


void filterRed(){
     tint(255, 0, 0);
     pg.image(cam, 0, 0, width, height); 
     pg.save("red.jpg");
}

Where did I lost? Any help is appreciated.

Thanks in advance- d

Tagged:

Answers

  • Answer ✓

    You're mixing up the main canvas and another PGraphics. You are using tint without pg. so it doesn't affect the PGraphics and you are also using PGraphics without begin/endDraw, which it should always have. So this code is incorrect. Instead you probably want to use begin/endDraw and pg.tint();

  • thanks amnon. So I'll test with

     void filterRed(){
         pg.beginDraw();     
         pg.tint(255, 0, 0);
         pg.image(cam, 0, 0, width, height); 
         pg.save("red.jpg");
         pg.endDraw();
    }
    
    
Sign In or Register to comment.