Need help! Mirroring text movement on x axis?

edited September 2015 in Library Questions

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)

  • edited September 2015 Answer ✓

    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:

    import gab.opencv.*;
    import processing.video.*;
    import java.awt.*;
    
    String text2 = "";
    
    Capture video;
    OpenCV opencv;
    
    void setup() {
      size(640, 480); //CHANGEED THIS LINE
      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/1.5), faces[i].y,width,width);//CHANGED THIS LINE
      }  
          popMatrix();
    }
    
    void captureEvent(Capture c) {
      c.read();
    }
    
  • 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?

  • edited October 2015

    @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.

Sign In or Register to comment.