Deren Guler – FaceOSC

by deren @ 11:54 pm 23 January 2012

I used applescript in Processing to control different application on my computer through face movements using the Cocoa library in Processing. I tried a few different applications but focused on Powerpoint because a friend of mine asked if I could hack Powerpoint to run through external gestures. I found an applescript handbook for Powerpoint 2004 which was compatible with my version of the program. The complete list of powerpoint commands can be found here
You can look up commands for most programs pretty easily and substitute different actions. I found that the mouth and eyebrow gestures were easiest to work with in terms of limiting the response rate to more dramatic gestures.

 

video coming…

Here is the code for Powerpoint 2004:

//
// a template for receiving face tracking osc messages from
// Kyle McDonald's FaceOSC https://github.com/kylemcdonald/ofxFaceTracker
//
// 2012 Dan Wilcox danomatika.com
// for the IACD Spring 2012 class at the CMU School of Art
//
// adapted from from Greg Borenstein's 2011 example
// http://www.gregborenstein.com/
// https://gist.github.com/1603230
//
import com.apple.cocoa.foundation.*; // to access applescript
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 eyeLeft;
float eyeRight;
float eyebrowLeft;
float eyebrowRight;
float jaw;
float nostrils;
 
void setup() {
size(640, 480);
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, "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);
stroke(0);
 
if(found > 0) {
translate(posePosition.x, posePosition.y);
scale(poseScale);
noFill();
ellipse(-20, eyeLeft * -9, 20, 7);
ellipse(20, eyeRight * -9, 20, 7);
ellipse(0, 20, mouthWidth* 3, mouthHeight * 3);
ellipse(-5, nostrils * -1, 7, 3);
ellipse(5, nostrils * -1, 7, 3);
rectMode(CENTER);
fill(0);
rect(-20, eyebrowLeft * -5, 25, 5);
rect(20, eyebrowRight * -5, 25, 5);
}
 
//some powerpoint commands
if (mouthWidth > 15){
String script = "tell application \"Microsoft PowerPoint\"" +"\n" + "go to next slide slideshow view of slide show window 1" + "\n" + "end tell";
executeScript(script);
}
 
if (mouthWidth < 15){
String script = "tell application \"Microsoft PowerPoint\"" +"\n" + "go to previous slide slideshow view of slide show window 1" + "\n" + "end tell";
executeScript(script);
 
}
 
if (eyebrowLeft > 8){
String script = "tell application \"Microsoft PowerPoint\"" +"\n" + "exit slide show slideshow view of slide show window 1 " + "\n" + "end tell";
executeScript(script);
}
 
if (eyebrowLeft < 6){
String script = "set theView to slide show view of theWindow " + "\n" + "end tell";
executeScript(script);
}
 
}
 
void executeScript(String script) {
NSAppleScript myScript = new NSAppleScript(script);
NSMutableDictionary errors = new NSMutableDictionary();
myScript.execute(errors);
}
 
// 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 eyeLeftReceived(float f) {
println("eye left: " + f);
eyeLeft = f;
}
 
public void eyeRightReceived(float f) {
println("eye right: " + f);
eyeRight = f;
}
 
public void eyebrowLeftReceived(float f) {
println("eyebrow left: " + f);
eyebrowLeft = f;
}
 
public void eyebrowRightReceived(float f) {
 
println("eyebrow right: " + f);
eyebrowRight = f;
}
 
public void jawReceived(float f) {
println("jaw: " + f);
jaw = f;
}
 
public void nostrilsReceived(float f) {
println("nostrils: " + f);
nostrils = f;
}
 
// all other OSC messages end up here
void oscEvent(OscMessage m) {
if(m.isPlugged() == false) {
println("UNPLUGGED: " + m);
}
}

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