Skip to content

Instantly share code, notes, and snippets.

@kasperkamperman
Created May 19, 2015 20:15
Show Gist options
  • Save kasperkamperman/b0a412d2a0a99f002856 to your computer and use it in GitHub Desktop.
Save kasperkamperman/b0a412d2a0a99f002856 to your computer and use it in GitHub Desktop.
FrameDifference problem Processing OpenCV library
/*
Problem. Why I see a light image of me, while I do a difference on exactly the same
images.
OpenCV for Processing 0.5.2 by Greg Borenstein http://gregborenstein.com
Using Java OpenCV 2.4.5.0
Processing 3.0a4
*/
import org.opencv.core.Mat;
import gab.opencv.*;
import processing.video.*;
Capture video;
OpenCV opencv;
PImage videoFrame;
PImage lastImg;
void setup()
{
size ( 640, 480 );
video = new Capture(this, width, height);
video.start();
opencv = new OpenCV( this, 640, 480);
videoFrame = new PImage( 640, 480 );
lastImg = new PImage( 640, 480 );
frameRate(30);
}
void draw()
{
//bubbles.add(new Bubble( (int)random( 0, width - 40), -bubblePNG.height, bubblePNG.width, bubblePNG.height)); // Adds a new bubble to the array with a random x position
if (video.available()) {
video.read();
// just store it in a PImage videoFrame
// to really make sure we use to save frame
// as lastImg. However this is not needed, just an extra check
videoFrame = video;
// load the frame in opencv.
// I suppose this overwrites the old image. However I'm not sure, since
// some noise is visible.
// I can't find something to empty it though.
opencv.loadImage(videoFrame);
// normally we do this here
// but to show the problem I want to find the difference between
// two the same images. There should be a differce.
// but still there is.....
lastImg = videoFrame;
// difference with the lastImg (actually the videoFrame)
opencv.diff(lastImg);
// display the opencv output
image( opencv.getOutput(), 0, 0 );
// set the last Image to this videoFrame
// normal location
//lastImg = videoFrame;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment