Created
May 19, 2015 20:35
-
-
Save kasperkamperman/0605812c7fb35515ac6c to your computer and use it in GitHub Desktop.
frameDifference with Mat OpenCV library for Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.opencv.core.Mat; | |
import gab.opencv.*; | |
import processing.video.*; | |
Capture video; | |
OpenCV opencv; | |
Mat cvLastFrameMat; | |
Mat cvThisFrameMat; | |
void setup() | |
{ | |
size ( 640, 480 ); | |
video = new Capture(this, width, height); | |
video.start(); | |
opencv = new OpenCV( this, 640, 480); // Initialises the OpenCV library | |
// Any idea how to create an empty Mat? | |
// new Mat(640, 480, 0); gives an error however cols and rows seem correct | |
cvLastFrameMat = opencv.getGray(); | |
//println(cvLastFrame.cols()); | |
frameRate(25); | |
} | |
void draw() | |
{ | |
if (video.available()) { | |
video.read(); | |
opencv.loadImage(video); | |
cvThisFrameMat = opencv.getGray(); | |
// difference with last Mat and this Mat | |
// result is stored in this Mat | |
OpenCV.diff(cvThisFrameMat, cvLastFrameMat); | |
image( opencv.getOutput(), 0, 0 ); | |
// this gives a strange grid, so we do load image again | |
//OpenCV.toCv(video, cvLastFrameMat); | |
opencv.loadImage(video); | |
cvLastFrameMat = opencv.getGray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment