Jonathan – Face OSC

by jonathan @ 1:48 am 24 January 2012

I wanted to have a little fun with this part of Project 1. I took a quick picture of my friend Ethan, and used his image as the little avatar in my game. My aim of this program was to just get a bit familiar with how OSC functions as well as how the library Face OSC works. The object of the game is to catch the little balls in Ethan’s mouth controlled by the movements of your own mouth. Though this interaction is nothing special, my mental image of people’s opening and closing mouths while sitting at their computer completely engrossed with the game was especially comical, which in the end was a good enough reason for me to make it. Overall the face tracking was surprisingly accurate and held calibration pretty easily, to my surprise. I had expected many more hiccups along the way, but was quite pleasantly surprised not to run into nothing I couldn’t easily troubleshoot myself. What I am looking forward is to keep challenging myself and to keep exploring various modes of interactions.

import oscP5.*;
import netP5.*;
 
float poseScale;
PVector posePosition = new PVector();
PVector poseOrientation = new PVector();
 
OscP5 oscP5;
 
int found, x, y, ellipseSize, score;
float mouthHeight, mouthWidth, totalMouthHeightB, totalMouthHeightT;
PImage eT, eB;
 
void setup() {
  size(640, 480);
  background(255);
 
  eT = loadImage("ethantop.jpg");
  eB = loadImage("ethanbottom.jpg");
  x = 0;
  y = int(random(1, 10));
  score = 0;
  ellipseSize = int(random(20, 50));
  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, "eyeLeftReceived", "/gesture/eye/left");
  oscP5.plug(this, "eyeRightReceived", "/gesture/eye/right");
  oscP5.plug(this, "eyebrowLeftReceived", "/gesture/eyebrow/left");
  oscP5.plug(this, "eyebrowRightReceived", "/gesture/eyebrow/right");
  oscP5.plug(this, "jawReceived", "/gesture/jaw");
  oscP5.plug(this, "nostrilsReceived", "/gesture/nostrils");
}
 
void draw() {
  background(255);
  smooth();
  totalMouthHeightB = 22+mouthHeight;
  totalMouthHeightT = -mouthHeight*4;
 
  flyingObjects();
  eating();
}
 
void eating() {
  if (found > 0) {
    //draw image
    image(eB, 0+posePosition.x, posePosition.y-100+totalMouthHeightB, eB.width/12, eB.height/12);
    image(eT, 8+posePosition.x, posePosition.y-100+totalMouthHeightT, eT.width/12, eT.height/12);
  }
}
 
void flyingObjects() {
  x = x + int(random(1, 10));
  fill(random(255), random(255), random(255));
  noStroke();
  //println(y);
  ellipseMode(CENTER);
  //draw balls
  ellipse(x, y, ellipseSize, ellipseSize);
  //check for border
  if (x > width) {
    x = 0;
    y = int(random(height/2));
    ellipseSize = int(random(20, 30));
  }
  //check for hit
  if (y > posePosition.y-100+totalMouthHeightT && y  posePosition.x - 1 && x < posePosition.x + 2 ) {
    x = 0;
    score = score+1;
    y = int(random(height/2));
    ellipseSize = int(random(20, 30));
    background (255, 0, 0);
    //println("hit");
  }
 
  //score
  textSize(100);
  fill(0);
  text(score, width-110, 100);
  println(score);
}
 
public void found(int i) {
  println("found: " + i);
  found = i;
}
 
public void posePosition(float x, float y) {
  println("pose position\tX: " + x + " Y: " + y );
  posePosition.set(x, y, 0);
}
 
public void mouthWidthReceived(float w) {
  println("mouth Width: " + w);
  mouthWidth = w;
}
 
public void mouthHeightReceived(float h) {
  println("mouth height: " + h);
  mouthHeight = h;
}

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2023 Interactive Art and Computational Design, Spring 2012 | powered by WordPress with Barecity