How to flip video from FaceOSC?

edited October 2016 in How To...

Hi all,

I am new to the Processing and now trying to use FaceOSC. Everything was done already, but it is hard to play the game I made when everything is not a mirror view. So I want to flip the video or data that FaceOSC sent to processing.

I'm not sure if FaceOSC sent the video because I've tried flip like a video but it doesn't work. I also flipped like a image (); line but still doesn't work.

//XXXXXXX// This is some of my code.

import oscP5.*;
 import codeanticode.syphon.*;

 OscP5 oscP5;
SyphonClient client;

PGraphics canvas;

boolean found;
PVector[] meshPoints;

void setup() {
size(640, 480, P3D);
frameRate(30);
initMesh();

oscP5 = new OscP5(this, 8338);

// USE THESE 2 EVENTS TO DRAW THE 
 // FULL FACE MESH:
  oscP5.plug(this, "found", "/found");
  oscP5.plug(this, "loadMesh", "/raw");
  // plugin for mouth
  oscP5.plug(this, "mouthWidthReceived", "/gesture/mouth/width");
  oscP5.plug(this, "mouthHeightReceived", "/gesture/mouth/height");
      // initialize the syphon client with the name of the server
  client = new SyphonClient(this, "FaceOSC");
  // prep the PGraphics object to receive the camera image
  canvas = createGraphics(640, 480, P3D);

}

void draw() {  
  background(0);
  stroke(255);
// flip like a vdo here, does not work
     /* pushMatrix(); 
  translate(canvas.width, 0);
  scale(-1,1);
  image(canvas, -canvas.width, 0, width, height);  
  popMatrix(); */

  image(canvas, 0, 0, width, height); 


  if (found) {
    fill(100);
    drawFeature(faceOutline);
    drawFeature(leftEyebrow);
    drawFeature(rightEyebrow);
    drawFeature(nosePart1);   
    drawFeature(nosePart2);           
    drawFeature(leftEye);     
    drawFeature(rightEye);        
    drawFeature(mouthPart1);  
    drawFeature(mouthPart2);  
    drawFeature(mouthPart3);
    drawFeature(mouthPart4);
    drawFeature(mouthPart5);
  }


 }
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void drawFeature(int[] featurePointList) {
  for (int i = 0; i < featurePointList.length; i++) {
    PVector meshVertex = meshPoints[featurePointList[i]];
    if (i > 0) {
      PVector prevMeshVertex = meshPoints[featurePointList[i-1]];
 line(meshVertex.x, meshVertex.y, prevMeshVertex.x, prevMeshVertex.y);
}
ellipse(meshVertex.x, meshVertex.y, 3, 3);
  }
}
/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
public void found(int i) {
  // println("found: " + i); // 1 == found, 0 == not found
  found = i == 1;
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Answers

  • @TuangPing -- were you able to resolve this issue?

    Here is an old thread with many approaches to flipping images. It talks about the the scale() method you are attempting, and other methods.

    Further information in the forums on 'flip' and 'mirror':

  • Here is an example sketch:

    /** Flip Mirror Sketches
     *  2016-10-23 Processing 3.2.1
     *  Flip or mirror drawing between pushMatrix &popMatrix.
     *  Useful for camera interaction.
     *  https:// forum.processing.org/two/discussion/18571/
     **/
    
    PImage img;
    
    void setup(){
      size(512,512);
      img = loadImage("https://forum.processing.org/processing-org.jpg");
      strokeWeight(4);
    }
    
    void draw(){
      background(0);
    
      // start flipping
      if(keyPressed){
        pushMatrix();
        translate(width,0);
        scale(-1,1);
      }
    
      // flip drawing
      image(img,0,0);
      triangle(0,height/3,width,height/2,0,2*height/3);
    
      // stop flipping
      if(keyPressed){
        popMatrix();
      }
    
      // no flip drawing
      rect(0,0,width/4,height/4); 
    }
    

    FlipMirrorSketches2

  • edited October 2016

    @jeremydouglass

    Thanks for the help. Actually, I have read some of the links you provided before asking a question, and already tried them, but it didn't work out. My friend came help and told me about the pushMatrix(); and popMatrix(); method. This was why my code didn't work out. He figured it out that I out the popMatrix in the wrong place, which I wouldn't never known how to make it right. Huhh ~_~ It always hard for someone who's not a programmer to solve this kind of problem.

    Anyway, Thank you for your help again.

Sign In or Register to comment.