Commit 3fa75aed authored by Axel's avatar Axel
Browse files

Update Final version /src/imageform.cpp, Final version /src/imageform.h, Final...

Update Final version /src/imageform.cpp, Final version /src/imageform.h, Final version /src/main.cpp, Final version /src/ofApp.cpp, Final version /src/ofApp.h files
parent affc15c1
#include "imageform.h"
void Form::postRandom()
{
myfont.drawString("Occupation: " + RandomOcc,600,180);
myfont.drawString("Hobby: " + RandomHob,600,280);
myfont.drawString("Wealth: " + RandomWea,600,380);
myfont.drawString("Dislikes: " + RandomDis,600,480);
};
void Form::updateRandom()
{
RandomOcc = Occupation[ofRandom(Occupation.size())];
RandomHob = Hobby[ofRandom(Hobby.size())];
RandomWea = Wealth[ofRandom(Wealth.size())];
RandomDis = Dislikes[ofRandom(Dislikes.size())];
};
void Form::updateFields()
{
if (FanMode && !SciMode)
{
myfont.load("mael.ttf", 24);
Occupation = scanFiles("Occupation_Fan.txt");
Hobby = scanFiles("Hobby_Fan.txt");
}
else if (!FanMode && SciMode)
{
myfont.load("alienencounters.ttf", 24);
Occupation = scanFiles("Occupation_Sci.txt");
Hobby = scanFiles("Hobby_Sci.txt");
}
else if (!FanMode && !SciMode)
{
myfont.load("arial.ttf", 24);
Occupation = scanFiles("Occupation.txt");
Hobby = scanFiles("Hobby.txt");
}
else
{
myfont.load("arial.ttf", 24);
Occupation = scanFiles("Occupation.txt");
Hobby = scanFiles("Hobby.txt");
}
Wealth = scanFiles("Wealth.txt");
Dislikes = scanFiles("Dislikes.txt");
};
std::vector<std::string> Form::scanFiles(std::string filename)
{
std::vector<std::string> array;
ofBuffer buffer = ofBufferFromFile(filename);
for (auto line : buffer.getLines()){
array.push_back(line);
}
return array;
}
std::vector<std::string> Form::addFiles(std::vector<std::string> results, std::string filename)
{
ofBuffer buffer = ofBufferFromFile(filename);
for (auto line : buffer.getLines()) {
results.push_back(line);
}
return results;
}
void Form::startFanMode()
{
SciMode = false;
FanMode = true;
updateFields();
updateRandom();
}
void Form::startSciMode()
{
FanMode = false;
SciMode = true;
updateFields();
updateRandom();
}
void Form::startRegMode()
{
FanMode = false;
SciMode = false;
updateFields();
updateRandom();
}
\ No newline at end of file
#pragma once
//include <iostream>
#include <vector>
#include "ofMain.h"
#include "ofxFaceTracker.h"
class Form
{
public:
std::vector<string> Occupation;
std::vector<string> Hobby;
std::vector<string> Wealth;
std::vector<string> Dislikes;
string RandomOcc;
string RandomHob;
string RandomWea;
string RandomDis;
bool FanMode;
bool SciMode;
void updateFields();
void updateRandom();
void postRandom();
void startFanMode();
void startSciMode();
void startRegMode();
ofTrueTypeFont myfont;
std::vector<std::string> scanFiles(std::string filename);
std::vector<std::string> addFiles(std::vector<std::string> results, std::string filename);
};
#include "ofApp.h"
int main() {
ofSetupOpenGL(1024, 720, OF_WINDOW);
return ofRunApp(std::make_shared<ofApp>());
}
#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();
sad = false;
happy = false;
talking = false;
tired = false;
verdana.load("verdana.ttf", 20, true, true);
verdana.setLineHeight(34.0f);
verdana.setLetterSpacing(1.035);
}
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();
ofSetColor(150);
verdana.drawString("mood : " + mood, 10, ofGetHeight() - 100);
verdana.drawString("tired : " + tiredMood, 10, ofGetHeight() - 75);
verdana.drawString("talking : " + talkingMood, 10, ofGetHeight() - 50);
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 < 12.5f) {
sad = true;
mood = "sad";
//std::cout << "Sad" << endl;
}
if (mouthW >= 12.5f && mouthW <= 13.5f) {
normal = true;
mood = "normal";
//std::cout << "normal" << endl;
}
if (mouthW > 13.5f) {
happy = true;
mood = "happy";
//std::cout << "Happy" << endl;
}
if (left_eyeOpen < 2.8f && right_eyeOpen < 2.8f) {
tired = true;
tiredMood = "yes";
//std::cout << "Tired" << endl;
}
if (left_eyeOpen > 2.8f && right_eyeOpen > 2.8f) {
tired = false;
tiredMood = "no";
//std::cout << "Not tired" << endl;
}
if (mouth_Open > 23.0f) {
talking = true;
talkingMood = "yes";
//std::cout << "Talking" << endl;
}
if (mouth_Open < 23.0f) {
talking = false;
talkingMood = "no";
//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);
mood = "";
tiredMood = "";
talkingMood = "";
}
ofPopMatrix();
}
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();
}
}
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);
}
}
void ofApp::drawButtons()
{
drawButtonFan();
drawButtonSci();
drawButtonReg();
}
void ofApp::drawButtonFan()
{
ofPushStyle();
ofSetColor(FanCol);
ofDrawRectangle(400, 50, 150, 50);
ofPopStyle();
ofPushStyle();
ofSetColor(FanColText);
fontFan.drawString("Fantasy Mode", 410, 75);
ofPopStyle();
}
void ofApp::drawButtonSci()
{
ofPushStyle();
ofSetColor(SciCol);
ofDrawRectangle(600, 50, 150, 50);
ofPopStyle();
ofPushStyle();
ofSetColor(SciColText);
fontSci.drawString("Sci-Fi Mode", 610, 75);
ofPopStyle();
}
void ofApp::drawButtonReg()
{
ofPushStyle();
ofSetColor(RegCol);
ofDrawRectangle(800, 50, 150, 50);
ofPopStyle();
ofPushStyle();
ofSetColor(RegColText);
fontReg.drawString("Regular Mode", 810, 75);
ofPopStyle();
}
#pragma once
#include "ofMain.h"
#include "ofxCv.h"
#include "ofxFaceTracker.h"
#include "imageform.h"
#include <iostream>
class ofApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void mousePressed(int x, int y, int button);
ofVideoGrabber cam;
ofxFaceTracker tracker;
ofEasyCam easyCam;
ofVboMesh vboMesh;
std::string mood;
std::string tiredMood;
std::string talkingMood;
bool happy;
bool sad;
bool normal;
bool tired;
bool talking;
Form myForm;
ofColor FanCol;
ofColor FanColText;
ofColor SciCol;
ofColor SciColText;
ofColor RegCol;
ofColor RegColText;
ofTrueTypeFont fontFan;
ofTrueTypeFont fontSci;
ofTrueTypeFont fontReg;
ofTrueTypeFont verdana;
void drawButtonFan();
void drawButtonSci();
void drawButtonReg();
void drawButtons();
void modeCheck();
};
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