Seismograph
in
Core Library Questions
•
1 year ago
he folks, i am rather new to processing and I stuck with a problem. I try to visualize a motion detection with a line like a seismograph - so the line should grow over time. I tried a lot but it seems I am stumped. I post the most clear code with no experiments...
Any help is very appreciated.
ty B
Any help is very appreciated.
ty B
- import processing.video.*;
Timer timer;
PImage prevFrame;
Capture video;
int totalTime = 500;
int arrayLength = totalTime/int(frameRate);
float[] r1 = new float[arrayLength];
float threshold = 30;
int x = 0;
void setup() {
size(320, 240);
smooth();
background(0);
video = new Capture(this, width, height, 5);
prevFrame = createImage(video.width, video.height, RGB);
timer = new Timer(totalTime);
timer.start();
for (int i = 0; i < r1.length; i++) {
r1[i]=0;
}
}
void draw() {
if (video.available()) {
prevFrame.copy(video, 0, 0, video.width, video. height, 0, 0, video.width, video.height);
prevFrame.updatePixels();
video.read();
}
loadPixels();
video.loadPixels();
prevFrame.loadPixels();
//// motion detection
float totalMotion = 0;
for (int i = 0; i <video.pixels.length; i++) {
color fgColor = video.pixels[i];
color bgColor = prevFrame.pixels[i];
float r1 = red(fgColor);
float g1 = green(fgColor);
float b1 = blue(fgColor);
float r2 = red(bgColor);
float g2 = green(bgColor);
float b2 = blue(bgColor);
float diff = dist(r1, g1, b1, r2, g2, b2);
totalMotion += diff;
}
float avgMotion =totalMotion/video.pixels.length;
/// average motion over certain time
for (int i = 0; i < r1.length-1; i ++ ) {
r1[i] = r1[i+1];
}
r1[r1.length-1]=avgMotion;
float sum = 0;
for (int i = 0; i < r1.length; i++) {
sum +=r1[i];
}
float avgMinute = sum/(totalTime/100);
float r = avgMotion*2;
if (timer.isFinished()) {
println(avgMinute);
x+=5;
stroke(255);
noFill();
strokeWeight(1);
//// draw spline
beginShape();
curveVertex(x, avgMinute);
endShape();
timer.start();
}
}
1