We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there, I am using openCV and face detection to control the transparency of images. The position of the detected face on the x axis controls transparency. What I would like to do is be able to ignore the other faces that get picked up by the webcam. Is there a way to get the value of face 1 and ignore face 2, face 3, face 4 etc., but upon face 1 being killed, make face 2 = face 1, face 3 = face 2 etc., and constantly only use the data from face 1 as the controlling parameter?
I have looked into the OpenCV example (Example: Whichface) and I can't seem to wrangle it to what i need it for. Here is my existing code
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
Capture video;
OpenCV opencv;
PImage ed;
PImage genie;
int offset = 0;
float easing = 0.05;
void setup() {
size(724,960);
video = new Capture(this, 640/2, 480/2);
opencv = new OpenCV(this, 640/2, 480/2);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
video.start();
ed = loadImage("ed.jpg");
genie = loadImage("genie.jpg");
}
void draw() {
scale(1);
opencv.loadImage(video);
noFill();
stroke(0, 255, 0);
strokeWeight(3);
Rectangle[] faces = opencv.detect();
println(faces.length);
for (int i = 0; i < faces.length; i++) {
tint(255, 230); // Display at half opacity
image(genie, 0, 0); // Display at full opacity
int dx = (faces[i].x-genie.width/2) - offset;
offset += dx * easing;
tint(255, faces[i].x); // Display at half opacity
image(ed, 0, 0);
}
}
void captureEvent(Capture c) {
c.read();
}
Answers
Hi, You could simply say :