We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to make the the wave that I have follow my face on openCV face detector but i can't seem to rearrange it so it works. right now it works with just the wave following the mouse but how do I make it follow my face on my webcam instead of the mouse. how do i rearrange it so it works? any help would be very much appreciated! this is the code I have right now:
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
Capture video;
OpenCV opencv;
// creating the wave -> (ellipses transform into wave as it grows and dies
class Wave {
PVector loc;
int farOut;
Wave() {
loc = new PVector();
loc.x = mouseX;
loc.y = mouseY;
farOut = 1;
//colour stroke on wave set on random so it flashes.
stroke(random(255), random(255), random(255));
}
void update() {
farOut += 1;
}
void display() {
ellipse(loc.x, loc.y, farOut, farOut);
}
boolean dead() {
if(farOut > 90) {
return true;
}
return false;
}
}
//array list of waves
ArrayList<Wave> waves = new ArrayList<Wave>();
void setup() {
size(640, 480);
video = new Capture(this, 640/2, 480/2);
opencv = new OpenCV(this, 640/2, 480/2);
//dectating just the face
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
ellipseMode(CENTER);
video.start();
}
void draw() {
scale(2);
opencv.loadImage(video);
image(video, 0, 0 );
fill(255, 255, 255, 50);
noStroke();
//face detector code with openCV
Rectangle[] faces = opencv.detect();
println(faces.length);
for (int i = 0; i < faces.length; i++) {
println(faces[i].x + "," + faces[i].y);
ellipse(faces[i].x, faces[i].y, 10, 10);
Wave w = new Wave();
//array list -> creating new waves
waves.add(w);
}
//run through each of the waves
//wave size will grow
for(int i = 0; i < waves.size(); i ++) {
//show waves - > each wave updated and displayed
waves.get(i).update();
waves.get(i).display();
//kill the wave
if(waves.get(i).dead()) {
waves.remove(i);
}
}
}
void captureEvent(Capture c) {
c.read();
}
Answers
Try This
and then tell what is not working
@blyk is there a reason why we cant use elipse rather then Rectangle[] faces = opencv.detect(); ? i just like the look of the egg or circle shape rather then the usual box....thanks also is there a way rather then using this ellipse(loc.x, loc.y, farOut, farOut); that you made maybe we can use wave amplitudes from vocals? on to the bottom corner of the face detect Rectangle[] ?
this is what i done so far
i cant get the sound waves to appear only near faces and on top of all the video is jumpy and im not sure why ? i have a pretty fast pc so it cant be my processor or graphics card so then what ?
i would like to see this amplitudes shorten and stacked to the bottom of the rectangle of faces when they get detected