Skip to content

Instantly share code, notes, and snippets.

@tado
Last active August 29, 2015 14:22
Show Gist options
  • Save tado/0a9d53c94b82d16f2614 to your computer and use it in GitHub Desktop.
Save tado/0a9d53c94b82d16f2614 to your computer and use it in GitHub Desktop.
Facetracker : face modify example
#include "testApp.h"
using namespace ofxCv;
void testApp::setup() {
ofSetVerticalSync(true);
cam.initGrabber(640, 480);
tracker.setup();
ofBackground(0);
}
void testApp::update() {
cam.update();
if(cam.isFrameNew()) {
tracker.update(toCv(cam));
}
}
void testApp::draw() {
ofSetColor(255);
ofDrawBitmapString(ofToString((int) ofGetFrameRate()), 10, 20);
// 顔を検出したら
if(tracker.getFound()) {
// 検出した顔のメッシュをとりだし
ofMesh mesh = tracker.getObjectMesh();
// 30番の頂点(鼻先)のZ座標を前へ
mesh.setVertex(30, ofVec3f(mesh.getVertex(30).x, mesh.getVertex(30).y, mesh.getVertex(30).z - 10));
// 口角(48, 54)を吊り上げ
mesh.setVertex(48, ofVec3f(mesh.getVertex(48).x - 2, mesh.getVertex(48).y - 6, mesh.getVertex(48).z + 4));
mesh.setVertex(54, ofVec3f(mesh.getVertex(54).x + 2, mesh.getVertex(54).y - 6, mesh.getVertex(54).z + 4));
// 変更した顔を描画
ofEnableDepthTest();
easyCam.begin();
ofScale(10, -10, -8);
cam.getTextureReference().bind();
mesh.draw();
cam.getTextureReference().unbind();
easyCam.end();
ofDisableDepthTest();
}
}
void testApp::keyPressed(int key) {
if(key == 'r') {
tracker.reset();
}
}
#pragma once
#include "ofMain.h"
#include "ofxCv.h"
#include "ofxFaceTracker.h"
class testApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed(int key);
ofVideoGrabber cam;
ofxFaceTracker tracker;
ofEasyCam easyCam;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment