How to properly use filters with video capture? problem with flickering

edited December 2016 in Library Questions

I'm trying to apply filter() to live video and found some strange effects. It may be that I have simply missed some documentation, which would be great to see. Can anyone let me know why these different effects are occurring?

Thanks everyone,

Woody

The code below works fine to just display the plain video, here is a list of effects noticed when different lines after image(cam, 0, 0); are uncommented:

   filter(INVERT);

inverts the colours of the image as expected

filter(THRESHOLD,0.5);

shows a black/white image as expected

vid.filter(THRESHOLD);

Shows a black/white image. This is strange because I haven't modified the variable cam. I expected any change made to variable vid not to effect variable cam, however they appear to only be pointers perhaps? Is it possible to make an actual new copy of the video and modify them with separate filters?

cam.filter(INVERT);

gives a fast flickering grey image, with occasional visible inverted and non inverted frames. I expected this to work in the same way as filter(INVERT); I don't understand what is going on here?

vid.filter(INVERT);

Same as cam.filter(INVERT)

Factors that don't change the effects:

changing render from P3D to P2D or the default changing the frame rate and/or resolution of the video (at first I suspected that it might be an issue of CPU power but this would suggest that isn't the problem)

import processing.video.*;
PImage img;

Capture cam;

void setup() {
  size(540, 540, P3D);

  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]);
    }

    // The camera can be initialized directly using an 
    // element from the array returned by list():
    cam = new Capture(this, cameras[2]);
    cam.start();     
  }
}

void draw() {

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

   PImage vid=cam;


  image(cam, 0, 0);


  // filter(INVERT);
  // filter(THRESHOLD,0.5);
  // vid.filter(INVERT);
  // vid.filter(THRESHOLD);
  // cam.filter(INVERT);


}

Answers

  • Yes, same variable reference if you are using tje assignation symbol aka =. Check the image documentation. You could use cam.get() or copy() to get an actual copy.

    For the invert case, could it ne that you are applying inversion on an inverted image? In that case you would get the same original image.

    Kf

Sign In or Register to comment.