Commit eb70b785 authored by Robert Goddard's avatar Robert Goddard
Browse files

Upload New File

parent d84d6dc4
#include "ofApp.h"
using namespace ofxCv;
void ofApp::setup() {
//Set a constant screen refresh rate to reduce lag and stutters
ofSetVerticalSync(true);
cam.setup(320, 240);
//Setup face tracker
tracker.setup();
ofSetBackgroundColor(255);
FanCol = ofColor(245, 222, 179); //Parchment Colour
FanColText = ofColor(61, 55, 46); //Ink Color
SciCol = ofColor(66); //Machine Grey
SciColText = ofColor(24, 177, 246); //Electric Blue Text for Scifi
RegCol = ofColor(255); //White
RegColText = ofColor(0); //Black
fontFan.load("mael.ttf", 11);
fontSci.load("alienencounters.ttf", 15);
fontReg.load("arial.ttf", 11);
myForm.updateFields();
myForm.updateRandom();
}
void ofApp::update() {
cam.update();
//Update the tracker if a face is detected
if(cam.isFrameNew()) {
tracker.update(toCv(cam));
}
}
void ofApp::draw() {
ofSetColor(255);
cam.draw(0, 0, 320, 240);
//Show the frames per second to the user
ofDrawBitmapString(ofToString((int) ofGetFrameRate()), 10, 20);
//Print the values of the various face features to the console
std::cout << "Mouth width: " << tracker.getGesture(ofxFaceTracker::MOUTH_WIDTH) << endl;
std::cout << "Eye openness - Left eye:" << tracker.getGesture(ofxFaceTracker::LEFT_EYE_OPENNESS) << "Right eye:" << tracker.getGesture(ofxFaceTracker::RIGHT_EYE_OPENNESS) << endl;
std::cout << "Mouth open: " << tracker.getGesture(ofxFaceTracker::JAW_OPENNESS) << endl;
modeCheck();
myForm.postRandom();
drawButtons();
ofPushMatrix();
ofSetColor(255);
//Draw the face outlines and features if face is detected
if (tracker.getFound()) {
tracker.draw();
//Set the tracker outlines to variables
ofMesh objectMeshMod = tracker.getObjectMesh();
ofMesh meanMeshMod = tracker.getMeanObjectMesh();
//Set all the values of the various face features to floats
float mouthW = tracker.getGesture(ofxFaceTracker::MOUTH_WIDTH); //Avg width 15
float right_eyeOpen = tracker.getGesture(ofxFaceTracker::RIGHT_EYE_OPENNESS); //Avg openness 3.1
float left_eyeOpen = tracker.getGesture(ofxFaceTracker::LEFT_EYE_OPENNESS); //Avg openness 3.1
float mouth_Open = tracker.getGesture(ofxFaceTracker::JAW_OPENNESS); //Avg openness 22.0
//Setup the empty face
ofSetupScreenOrtho(1024, 720, -1000, 1000);
ofTranslate(ofGetWidth() / 5, ofGetHeight()*3/5);
//Set the scale
ofScale(5, 5, 5);
//Bind and draw the textures
cam.getTexture().bind();
meanMeshMod.draw();
cam.getTexture().unbind();
if (mouthW < 14.0f) {
sad = true;
//std::cout << "Sad" << endl;
}
if (mouthW > 14.0f) {
happy = true;
//std::cout << "Happy" << endl;
}
if (left_eyeOpen < 2.8f && right_eyeOpen < 2.8f) {
tired = true;
//std::cout << "Tired" << endl;
}
if (left_eyeOpen > 2.8f && right_eyeOpen > 2.8f) {
tired = false;
//std::cout << "Not tired" << endl;
}
if (mouth_Open > 22.0f) {
talking = true;
//std::cout << "Talking" << endl;
}
if (mouth_Open < 22.0f) {
talking = false;
//std::cout << "Not talking" << endl;
}
}else {
//If no face is detected warn the user that it is searching for a face
ofSetColor(150);
ofDrawBitmapString("searching for face...", 10, ofGetHeight()-4);
}
ofPushMatrix();
}
void ofApp::keyPressed(int key) {
if(key == 'r') {
//Reset the face tracker is the face isn't detected properly
tracker.reset();
}
}
void ofApp::mousePressed(int x, int y, int button) {
if (ofGetMouseX() > 400 && ofGetMouseX() < 550 && ofGetMouseY() > 50 && ofGetMouseY() < 100)
{
myForm.startFanMode();
}
if (ofGetMouseX() > 600 && ofGetMouseX() < 750 && ofGetMouseY() > 50 && ofGetMouseY() < 100)
{
myForm.startSciMode();
}
if (ofGetMouseX() > 800 && ofGetMouseX() < 950 && ofGetMouseY() > 50 && ofGetMouseY() < 100)
{
myForm.startRegMode();
}
//Button functionality, made so if you press one you'll trigger the mode selected.
}
void ofApp::modeCheck()
{
if (!myForm.FanMode && !myForm.SciMode)
{
ofSetBackgroundColor(RegCol);
ofSetColor(RegColText);
}
else if (myForm.FanMode && !myForm.SciMode)
{
ofSetBackgroundColor(FanCol);
ofSetColor(FanColText);
}
else if (!myForm.FanMode && myForm.SciMode)
{
ofSetBackgroundColor(SciCol);
ofSetColor(SciColText);
}
else
{
ofSetBackgroundColor(255);
ofSetColor(0);
}
//Checking what mode the code is in before drawing the background and colouring the text to make sure it matches the button in question.
}
void ofApp::drawButtons()
{
drawButtonFan();
drawButtonSci();
drawButtonReg();
//Draw the buttons
}
void ofApp::drawButtonFan() //Specific code to draw the buttons for Fantasy Mode
{
ofPushStyle();
ofSetColor(FanCol);
ofDrawRectangle(400, 50, 150, 50);
ofPopStyle();
ofPushStyle();
ofSetColor(FanColText);
fontFan.drawString("Fantasy Mode", 410, 75);
ofPopStyle();
}
void ofApp::drawButtonSci() //Specific code to draw the buttons for Sci-Fi Mode
{
ofPushStyle();
ofSetColor(SciCol);
ofDrawRectangle(600, 50, 150, 50);
ofPopStyle();
ofPushStyle();
ofSetColor(SciColText);
fontSci.drawString("Sci-Fi Mode", 610, 75);
ofPopStyle();
}
void ofApp::drawButtonReg() //Specific code to draw the buttons for Regular Mode
{
ofPushStyle();
ofSetColor(RegCol);
ofDrawRectangle(800, 50, 150, 50);
ofPopStyle();
ofPushStyle();
ofSetColor(RegColText);
fontReg.drawString("Regular Mode", 810, 75);
ofPopStyle();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment