スポンサーリンク

Processing

Face Tracking

投稿日:

FaceTrakingを行ってみた。
いきなり難しいけど。oscP5(Open Sound Control)を学びたいがゆえに行いました。

田所さんのスライドに詳しくは掲載してあるのですが、コンパイルされたFaceOSCをダウンロード。本当に便利な世の中になったもんだ。

[openFrameworks + ofxFaceTracker] →(OSC)→ [Processing + oscP5]
で送信。

FaceTrakingコード

import oscP5.*;

// FaceOSCからのOSCを解析するFaceクラス
class Face {
  //OscP5のインスタンス
  OscP5 oscP5;
  // 検出された顔の数
  int found;
  // ポーズ
  float poseScale;
  PVector posePosition = new PVector();
  PVector poseOrientation = new PVector();
  // ジェスチャー
  float mouthHeight, mouthWidth;
  float eyeLeft, eyeRight;
  float eyebrowLeft, eyebrowRight;
  float jaw;
  float nostrils;

  //コンストラクター
  Face(int port) {
    //ポートを指定して、OscP5を初期化
    oscP5 = new OscP5(this, port);
  }
  // FaceOSCから送られてきたOSCを解析
  boolean parseOSC(OscMessage m) {
    if (m.checkAddrPattern("/found")) {
      // 顔検出数
      found = m.get(0).intValue();
      return true;
    }
    //ポーズ (スケール、位置、向き)
    else if (m.checkAddrPattern("/pose/scale")) {
      poseScale = m.get(0).floatValue();
      return true;
    } else if (m.checkAddrPattern("/pose/position")) {
      posePosition.x = m.get(0).floatValue();
      posePosition.y = m.get(1).floatValue();
      return true;
    } else if (m.checkAddrPattern("/pose/orientation")) {
      poseOrientation.x = m.get(0).floatValue();
      poseOrientation.y = m.get(1).floatValue();
      poseOrientation.z = m.get(2).floatValue();
      return true;
    }
    // ジェスチャー (口、目、眉、顎、鼻腔)
    else if (m.checkAddrPattern("/gesture/mouth/width")) {
      mouthWidth = m.get(0).floatValue();
      return true;
    } else if (m.checkAddrPattern("/gesture/mouth/height")) {
      mouthHeight = m.get(0).floatValue();
      return true;
    } else if (m.checkAddrPattern("/gesture/eye/left")) {
      eyeLeft = m.get(0).floatValue();
      return true;
    } else if (m.checkAddrPattern("/gesture/eye/right")) {
      eyeRight = m.get(0).floatValue();
      return true;
    } else if (m.checkAddrPattern("/gesture/eyebrow/left")) {
      eyebrowLeft = m.get(0).floatValue();
      return true;
    } else if (m.checkAddrPattern("/gesture/eyebrow/right")) {
      eyebrowRight = m.get(0).floatValue();
      return true;
    } else if (m.checkAddrPattern("/gesture/jaw")) {
      jaw = m.get(0).floatValue();
      return true;
    } else if (m.checkAddrPattern("/gesture/nostrils")) {
      nostrils = m.get(0).floatValue();
      return true;
    }
    return false;
  }

  // 現在の顔の状態を文字で出力
  String toString() {
    return "found: " + found + "\n"
      + "pose" + "\n"
      + " scale: " + poseScale + "\n"
      + " position: " + posePosition.toString() + "\n"
      + " orientation: " + poseOrientation.toString() + "\n"
      + "gesture" + "\n"
      + " mouth: " + mouthWidth + " " + mouthHeight + "\n"
      + " eye: " + eyeLeft + " " + eyeRight + "\n"
      + " eyebrow: " + eyebrowLeft + " " + eyebrowRight + "\n"
      + " jaw: " + jaw + "\n"
      + " nostrils: " + nostrils + "\n";
  }

  //OSCメッセージが送られてきたら解析へ
  void oscEvent(OscMessage m) {
    parseOSC(m);
  }
};

faceClassコード

//Faceクラスのインスタンス
Face face;

void setup() {
  size(640, 480,P3D);
  frameRate(255);
  //Faceクラスを初期化
  face = new Face(8338);
}

void draw() {
  background(255);  
  stroke(0);
  

<blockquote>
  
  //もし顔が検出されたら
  if (face.found > 0) {
    //解析結果を文字で出力
  pushMatrix();
  translate(face.posePosition.x,face.posePosition.y,0);
  scale(face.poseScale);
  rotateX(-face.poseOrientation.x);
  rotateY(-face.poseOrientation.y);
  rotateZ(face.poseOrientation.z);
  
  stroke(0);
  noFill();
  
  ellipse(0,0,40,50);
  fill(0);
  noStroke();
  
  ellipse(-8,face.eyebrowLeft*-1,10,2);
  ellipse(8,face.eyebrowLeft*-1,10,2);
  
  ellipse(-8,face.eyeLeft*-1,4,4);
  ellipse(8,face.eyeLeft*-1,4,4);

  ellipse(0,14,face.mouthWidth,face.mouthHeight);
  ellipse(-2,face.nostrils,3,1);
  ellipse(2,face.nostrils,3,1);
  popMatrix();
  
  print(face.toString());
}
}

以上で表情の認識ができたわけですが。
Open Sound Controlってなんやねんっと。

OpenSound Controlは様々なプラットフォーム間とのデータ通信を可能にする非常に便利な規格です。Processing, Flash, Max/MSPなどの間での通信が代表的です。

要はネットワークを繋げられるってことでローカル上であれば、ローカルからソフト間通信ができるのかと。
もうちょっと詳しく調べてみます。


スポンサーリンク


Originally posted 2015-12-02 01:45:27.

スポンサーリンク

-Processing
-,

Copyright© office606 , 2023 All Rights Reserved Powered by STINGER.