We are about to switch to a new forum software. Until then we have removed the registration on this forum.
The text in the sketch needs to be on the face and following the face. On x axis but it is moving the opposite direction.
code:
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
String text2 = "";
Capture video;
OpenCV opencv;
void setup() {
size(640*2, 480*2);
video = new Capture(this, 640, 480);
opencv = new OpenCV(this, 640, 480);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
textFont(createFont("Menlo",(5)));
video.start();
}
void draw() {
pushMatrix();
opencv.loadImage(video);
//background(0); //voor zwarte achtergrond onder tekst
scale(-1,1);// spiegelen van beeld
translate(-video.width, 0); //terug plaatsen in kader/
image(video, 0, 0); // activeer of deactiveer code voor vieobeeld of niet
scale(-1,1); // spiegel tekst nog een keer
textSize(40);
// text(text2, 30, 30);
textAlign(CENTER);
text2 = "Watching You";
// noFill();
// stroke(255, 0, 0);
// strokeWeight(300);
Rectangle[] faces = opencv.detect();
println(faces.length); //deactiveer voor geen print output in beeld
//scale(-1,1); // spiegel tekst nog een keer --- deze niet???
// I think the problem maybe somewhere?? V
for (int i = 0; i < faces.length; i++) {
println(faces[i].x + "," + faces[i].y); //deactiveer voor geen print output in beeld
// rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
text(text2,faces[i].x-width, faces[i].y,width,width);
}
popMatrix();
}
void captureEvent(Capture c) {
c.read();
}
Answers
please format your code
@koogs. like this? (sorry was my first question on this forum)
Hey Bart, It took a little fiddling, but... I think that this code is doing what you want. I changed the size of the visual space to match the size of the image and reversed "faces[i].x-width" in line 47. Also modified to compensate for space so now it looks like this "-(faces[i].x+width/1.5)". Full code as I have it:
THANKS! @aaronf you really helped me with figuring this out!!
Happy that I could help. Do you mind if I change this up a little more and use it as part of a Halloween piece that I'm doing at my school?
@aaronf. Of course you can! I don't mind. If you wand, maybe you can post the code here. I wonder what you made of it.