I’m trying to add two different filters to a video feed from a webcam. What I try to accomplish is an inverted, grayscale image to feed to multiple led strips. I also add a tint to make the strips a bit warmer.
The problem is though that I can’t seem to be able to add two filters at once. Either only the filter(GRAY) is working, or when I only have the filter(INVERT) in the code my video is flickering.
I have the following code at the end of the sketch:
The flickering occurs, because you are inverting the image on every frame.
Your webcam does not give you a new image on every frame, so when “video.available()” is false, you are inverting the the image from the last frame. An easy solution should be to put the filter-code inside of your conditional:
if (video.available()) {
video.read();
video.filter(INVERT);
video.filter(GRAY);
}
Thanks for your reply! I tried it and indeed the flickering stops. The only other problem I still have is that both filters don’t work together. It only does the invert now and not the greyscale, any idea how I fix that?
In a simple test, INVERT and GRAY work fine together on a PImage. They also seem to work fine when added to the basic Video Library “Loop” example sketch, in the movieEvent. Can you give an example of this not working?
Sorry for the late reply, I was abroad for the week. Thanks for looking into it! It’s weird that I don’t seem to get it to work. My processing patch is:
Your approach seems too complicated a place to try to debug your problem – and the sketch you shared isn’t testable, because I don’t know what an OPC is.
Can you start with a cam or video example, filter it, and see what happens?
Here is one based on the GettingStartedCapture example:
import processing.video.*;
Movie movie;
void setup() {
size(560, 406);
background(0);
movie = new Movie(this, "launch2.mp4");
movie.loop();
}
void draw() {
if (movie.available() == true) {
movie.read();
movie.loadPixels();
movie.filter(GRAY);
movie.filter(INVERT);
movie.updatePixels();
}
image(movie, 0, 0, width, height);
}
They seem to work fine. Using loadPixels and updatePixels may not be necessary, but are included just in case given your problem.
I was able to reproduce flickering on the Loop example if I added filtering to the function movieEvent(Movie m) rather than doing it in the draw() loop. Don’t modify the resulting pixels in the event helper function – that may be threaded / racing. Instead, modify pixels in the draw() loop as shown.