Hello processors!
I am working on my final for class and no matter WHAT I do I can't seem to figure this out! Can anyone out there PLEASE help? Your help would be GREATLY appreciated! I feel like I'm so close to figuring it out but just can't seem to get it...
So what I'm trying to do is combine both my equalizer code with the edge detection code. Instead of having the lines/pixels radiate off of the circle, I want it to come off of the edges of the body (vice versa = I'd like the edge detection/difference to show as an equalizer rather than random colored pixels).
Any sort of help or guidance would be GREATLY appreciated. I just want it to all be an amazing showcase where anyone can just come into the frame and do a little dance.
Thank you SO MUCH in advance.
Here is my code so far...
I am working on my final for class and no matter WHAT I do I can't seem to figure this out! Can anyone out there PLEASE help? Your help would be GREATLY appreciated! I feel like I'm so close to figuring it out but just can't seem to get it...
So what I'm trying to do is combine both my equalizer code with the edge detection code. Instead of having the lines/pixels radiate off of the circle, I want it to come off of the edges of the body (vice versa = I'd like the edge detection/difference to show as an equalizer rather than random colored pixels).
Any sort of help or guidance would be GREATLY appreciated. I just want it to all be an amazing showcase where anyone can just come into the frame and do a little dance.
Thank you SO MUCH in advance.
Here is my code so far...
- // http://anthonymattox.com/visualizing-sound-with-processing
import krister.Ess.*;
import processing.video.*;
PImage prevFrame;
float threshold = 50;
Capture cam;
FFT myfft;
AudioInput myinput;
int bufferSize=512;
float r = 50;
float w = 1;
float h = 1;
void setup() {
size(640,480);
frameRate(120);
//background(0);
noStroke();
fill(255);
smooth();
cam = new Capture(this, 640, 480,30);
prevFrame = createImage(cam.width,cam.height,RGB);
Ess.start(this);
myinput=new AudioInput(bufferSize);
myfft=new FFT(bufferSize*2);
myinput.start();
myfft.damp(.1);
myfft.equalizer(true);
myfft.limits(.005,.05);
}
void draw() {
//background(0);
noStroke();
// CAMERA
if (cam.available() == true) {
prevFrame.copy(cam,0,0,cam.width,cam.height,0,0,cam.width,cam.height); // Before we read the new frame, we always save the previous frame for comparison!
prevFrame.updatePixels();
cam.read();
image(cam, 0, 0);
loadPixels();
cam.loadPixels();
prevFrame.loadPixels();
// Begin loop to walk through every pixel
for (int x = 0; x < cam.width; x ++ ) {
for (int y = 0; y < cam.height; y ++ ) {
int loc = x + y*cam.width; // Step 1, what is the 1D pixel location
color current = cam.pixels[loc]; // Step 2, what is the current color
color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color
// Step 4, compare colors (previous vs. current)
float r1 = red(current); float g1 = green(current); float b1 = blue(current);
float r2 = red(previous); float g2 = green(previous); float b2 = blue(previous);
float diff = dist(r1,g1,b1,r2,g2,b2);
// Step 5, How different are the colors?
// If the color at that pixel has changed, then there is motion at that pixel.
if (diff > threshold) {
// If motion, display black
pixels[loc] = color(random(255),random(255),random(255));
} else {
// If not, display white
pixels[loc] = color(40);
}
}
}
updatePixels();
// CIRCLE
translate(width/2, height/2);
noFill();
noStroke();
//ellipse(0, 0, r*2, r*2);
float arclength = 0;
for (int i=0; i<bufferSize;i++) {
arclength += w/2;
float theta = arclength/r;
pushMatrix();
// polar to cartesian conversion
translate(r*cos(theta), r*sin(theta));
// rotate box
rotate(theta);
fill(255);
ellipse(random(100),random(100),(0 + myfft.spectrum[i]*400),.4);
popMatrix();
arclength += w/2;
}
}
}
public void audioInputData(AudioInput theInput) {
myfft.getSpectrum(myinput);
}
1