Face OSC
Since I was little one of my favorite character was Totoro from the movie My neighbour Totoro by Hayao Miyazaki. The way that Totoro moved around in the movie was so funny to me that I tried to change his size and tried to make him move with my face and change in size and shape when I moved my mouth and eyes. I think it was quite successful since I could move him around and change in sizes but I had trouble trying to resizing him since it was too big when I first had drawn it. Also another problem that was big was that the program wouldn’t recognise my face properly and every time I moved my mouth or eyes the program would loose me and not follow me effectively enough. (That’s why I couldn’t embed a post since the program would loose my face every two seconds and it would be cut off)
import oscP5.*;
OscP5 oscP5;
// num faces found
int found;
// pose
float poseScale;
PVector posePosition = new PVector();
PVector poseOrientation = new PVector();
// gesture
float mouthHeight;
float mouthWidth;
float leftEyebrowHeight;
float rightEyebrowHeight;
float eyeLeftHeight;
float eyeRightHeight;
float nostrilHeight;
float jaw;
void setup() {
size(800, 650);
frameRate(30);
oscP5 = new OscP5(this, 8338);
oscP5.plug(this, "found", "/found");
oscP5.plug(this, "poseScale", "/pose/scale");
oscP5.plug(this, "posePosition", "/pose/position");
oscP5.plug(this, "poseOrientation", "/pose/orientation");
oscP5.plug(this, "mouthWidthReceived", "/gesture/mouth/width");
oscP5.plug(this, "mouthHeightReceived", "/gesture/mouth/height");
oscP5.plug(this, "eyebrowLeftReceived", "/gesture/eyebrow/left");
oscP5.plug(this, "eyebrowRightReceived", "/gesture/eyebrow/right");
oscP5.plug(this, "eyeLeftReceived", "/gesture/eye/left");
oscP5.plug(this, "eyeRightReceived", "/gesture/eye/right");
oscP5.plug(this, "nostrilsReceived", "/gesture/nostrils");
oscP5.plug(this, "jawReceived", "/gesture/jaw");
}
void draw() {
background(255);
stroke(0);
if(found > 0) {
translate(posePosition.x, posePosition.y);
scale(poseScale*0.1);
noFill();
noStroke();
fill(220);
triangle(-50,30-leftEyebrowHeight*5, -75-leftEyebrowHeight*5,70, -30,140);
triangle(50,30-rightEyebrowHeight*5, 75+rightEyebrowHeight*5,70, 30,140);
beginShape();
curveVertex(-130,160);
curveVertex(0,80+mouthHeight*5);
curveVertex(120,160);
curveVertex(190+mouthWidth*5,500);
curveVertex(0,620);
curveVertex(-190-mouthWidth*5,500);
curveVertex(-130,160);
curveVertex(0,80+mouthHeight*5);
curveVertex(120,160);
endShape();
fill(255);
ellipse(-65,145,45+eyeLeftHeight*5,45+eyeLeftHeight*5);
ellipse(65,145,45+eyeRightHeight*5,45+eyeRightHeight*5);
ellipse(0,410, 300+mouthWidth*5,350+mouthHeight*5);
fill(0);
ellipse(-65,145,18+eyeLeftHeight*5,18+eyeLeftHeight*5);
ellipse(65,145,18+eyeRightHeight*5,18+eyeRightHeight*5);
triangle(0,175+nostrilHeight*5, 25,155+nostrilHeight*5, -25,155+nostrilHeight*5);
stroke(0);
strokeWeight(5);
line(0,250, -15,260);
line(0,250, 15,260);
line(50,260, 35,270);
line(50,260, 65,270);
line(-50,260, -65,270);
line(-50,260, -35,270);
line(25,280, 10,290);
line(25,280, 40,290);
line(-25,280, -10,290);
line(-25,280, -40,290);
line(70,285, 85,295);
line(70,285, 55,295);
line(-70,285, -55,295);
line(-70,285, -85,295);
}
}
// OSC CALLBACK FUNCTIONS
public void found(int i) {
println("found: " + i);
found = i;
}
public void poseScale(float s) {
println("scale: " + s);
poseScale = s;
}
public void posePosition(float x, float y) {
println("pose position\tX: " + x + " Y: " + y );
posePosition.set(x, y, 0);
}
public void poseOrientation(float x, float y, float z) {
println("pose orientation\tX: " + x + " Y: " + y + " Z: " + z);
poseOrientation.set(x, y, z);
}
public void mouthWidthReceived(float w) {
println("mouth Width: " + w);
mouthWidth = w;
}
public void mouthHeightReceived(float h) {
println("mouth height: " + h);
mouthHeight = h;
}
public void jawReceived(float f) {
println("jaw: " + f);
jaw = f;
}
public void eyebrowLeftReceived(float h) {
println("eyebrow left: " + h);
leftEyebrowHeight = h;
}
public void eyebrowRightReceived(float h) {
println("eyebrow right: " + h);
rightEyebrowHeight = h;
}
public void eyeLeftReceived(float h) {
println("eye left: " + h);
eyeLeftHeight = h;
}
public void eyeRightReceived(float h) {
println("eye right: " + h);
eyeRightHeight = h;
}
public void nostrilsReceived(float h) {
println("nostrils: " + h);
nostrilHeight = h;
}
// all other OSC messages end up here
void oscEvent(OscMessage m) {
/* print the address pattern and the typetag of the received OscMessage */
println("#received an osc message");
println("Complete message: "+m);
println(" addrpattern: "+m.addrPattern());
println(" typetag: "+m.typetag());
println(" arguments: "+m.arguments()[0].toString());
if(m.isPlugged() == false) {
println("UNPLUGGED: " + m);
}
}