Skip to content

Instantly share code, notes, and snippets.

@vinskim vinskim/BanksyInUs
Created Aug 18, 2018

Embed
What would you like to do?
BanksyInUs
import oscP5.*;
import processing.video.*;
import com.hamoid.*;
import java.util.Date;
OscP5 oscP5;
Capture cam;
Movie myMovie;
PFont Head;
PFont subTitle;
PImage light; //playing signal
PImage qBtn;//quitGame to Homescreen
PImage pBtn;//pause
PImage rBtn;//resetGame
//PImage loopBtn;//loop vid
PGraphics homeCanvas,canvas,showCanvas, printCanvas;
PVector[] meshPoints;
PVector posePosition, poseOrientation;
boolean found; //FaceOSC
Table infoTable, referTable, userTable;
PImage Btn01,Btn02,Btn03,Btn04,Btn05,btnOkay, btnYes, btnNo;//charSel Buttons
PImage bgd0, bgd1, bgd2, bgd3, bgd4, bgd5, bgd6;
PImage num1,num2,num3,num0,num0b, num0c, num0d;//count numbers to play game
PImage title_print,title_end;
///
float poseScale, posePos_x, posePos_y, poseOrt_x, poseOrt_y, poseOrt_z;
float leftEyebrowHeight, rightEyebrowHeight, eyeLeftHeight, eyeRightHeight, mouthWidth, mouthHeight, nostrilHeight;
int programFrame, videoFrame = 0, i;
//reference values
int NKframe;
float NKBrowL, NKBrowR, NKEyeL, NKEyeR, NKNose, NKMouthH, NKMouthW, NKOriX, NKOriY, NKOriZ;
boolean play=true, readytoPlay=false, gameMode =false, endOfClip = false, waittime= false;
char MENU = 'H';
//Home,Char,Game, Effect ,EMAIL&PRINT(Y),
char GAME = 'T'; //Tutorial, Play : clip plays again and player have to mimic the clip, Scores
int waveCount = 0;
int mouseOver=0;
PImage js,ksi,nk,bb,gm,gg,pew,pom,shane,title,layout;
String celebName="";
//settings
int score = 0, w=1920, h=1080; //w = 1440, h = 860, score =0;
String scoreString="", videoAddress = "", clipAddress = "";
void settings() {
size(w, h, P3D);
}
void setup() {
fullScreen();
jsonLoad();
setupNewUI();
noStroke();
smooth();
ellipseMode(CENTER);
//XXXXXXXXXXXXXXXXXX
//CAMERA PLUG-INS FOR LIVE PLAYING
//XXXXXXXXXXXXXXXXXX
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
}
//cam = new Capture(this, cameras[0]); //built in mac cam "isight"
//cam = new Capture(this,1280,960, "USB Camera");
cam = new Capture(this,1280,960, cameras[6]);
cam.start();
//FACEOSC PLUG-INS
posePosition = new PVector();
poseOrientation = new PVector();
initMesh();
oscP5 = new OscP5(this, 8338);
// USE THESE 2 EVENTS TO DRAW THE
// FULL FACE MESH:
oscP5.plug(this, "found", "/found");
oscP5.plug(this, "loadMesh", "/raw");
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, "mouthHeightReceived", "/gesture/mouth/height");
oscP5.plug(this, "mouthWidthReceived", "/gesture/mouth/width");
oscP5.plug(this, "nostrilsReceived", "/gesture/nostrils");
oscP5.plug(this, "jawReceived", "/gesture/jaw");
oscP5.plug(this, "posePosition", "/pose/position");
oscP5.plug(this, "poseScale", "/pose/scale");
oscP5.plug(this, "poseOrientation", "/pose/orientation");
//loadReferTable();
//referTable = loadTable("../csv/pew.csv", "header");
emailPrint();
//canvas = createGraphics(w, h, P3D);
frameRate(30);
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void draw() {
drawUI();
//loadReferTable();
//frameCount = programFrame;
//print ("MENU : " + MENU + " GAME :" +GAME +"\n");
if(GAME == 'P'){
comparison();
//println("PLAY : " + play);
//println("videoframe : " + videoFrame + " Mtime : "+round(myMovie.time()*100)/100.0 + " MDuration : "+ floor(myMovie.duration()*100)/100.0);
}
//exportFiles();///saveStringfile
//println("FC in draw: "+frameCount);
//println("FRAMECOUNT : "+frameCount+" SCORE : "+score);
//saveTable(infoTable, "table.csv");//,"html");
}
void mouseClicked(){
println("(",mouseX,",",mouseY,") MENU : "+MENU+" GAME :"+GAME);
}
String text1="",email="";
PImage userPhoto, postcard;
void keyPressed() {
if(MENU=='X'){
if (key==CODED){
if (keyCode==LEFT){
println ("left");
}else {
println ("unknown special key");
}
}else{
if (key==BACKSPACE) {
if (text1.length()>0) {
text1=text1.substring(0, text1.length()-1);
}
}else if (key==RETURN || key==ENTER) {
println ("ENTER");
email = text1;
println("email : "+email);
jsonSave();
text1="";
userPhoto = get(686, 239,532,756);//720, 200, 720, 430
userPhoto.save("finalPrint/"+userCount+userSel+userPost+".jpg");//WARN : keep saving.
sendMail(email);
printCommand = "lp -d Canon_TS9000_series_2 -o fit-to-page -o media=4x6.FullBleed /Users/admin/Documents/MerryChristmasNYC/finalPrint/"
+userCount+userSel+userPost+".jpg";
//printCommand = "lp -d "+"Canon_TS9000_series_2"+" "+"finalPrint/"+userCount+userSel+userPost+".jpg";
MENU='Y'; //'Y'
}else {
text1+=key;
}//println (text1);
}
}
}
/////////////////EMAIL MAIN/////////////////////////////////
// Simple E-mail Checking
// This code requires the Java mail library
// smtp.jar, pop3.jar, mailapi.jar, imap.jar, activation.jar
// Download:// <a href="http://java.sun.com/products/javamail/" target="_blank" rel="nofollow">http://java.sun.com/products/javamail/</a>
import javax.mail.*;
import javax.mail.internet.*;
// void setup() {
// size(200,200);
// sendMail();
// println("Finished.");
// noLoop();
// }
/////////////////AUTH///////////////////////////////////////
// Simple Authenticator
// Careful, this is terribly unsecure!!
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class Auth extends Authenticator {
public Auth() {
super();
}
public PasswordAuthentication getPasswordAuthentication() {
String username, password;
username = "yyyeeeeeyyy@gmail.com";
password = "itpWinter2017!";
System.out.println("authenticating... ");
return new PasswordAuthentication(username, password);
}
}
/////////////////MAIL STUFF/////////////////////////////////
// Example functions that send mail (smtp)
// You can also do imap, but that's not included here
// A function to check a mail account
import java.util.*;
import java.io.*;
import javax.activation.*;
// A function to send mail
void sendMail(String userEmail) {
// Create a session
String host="smtp.gmail.com";
Properties props=new Properties();
// SMTP Session
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
// We need TTLS, which gmail requires
props.put("mail.smtp.starttls.enable","true");
// Create a session
Session session = Session.getDefaultInstance(props, new Auth());
try
{
MimeMessage msg=new MimeMessage(session);
msg.setFrom(new InternetAddress("yyyeeeeeyyy@gmail.com", "HappyHolidayNYC"));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(userEmail));//"a@google.com"
msg.setSubject("Email with Processing");
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("Email sent with Processing");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource("/Users/admin/Documents/MerryChristmasNYC/finalPrint/"+userCount+userSel+userPost+".jpg");
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("image.jpg");
multipart.addBodyPart(messageBodyPart);
msg.setContent(multipart);
msg.setSentDate(new Date());
Transport.send(msg);
println("Mail sent!");
}
catch(Exception e)
{
e.printStackTrace();
}
}
// LISTS OF INDICES FOR EACH FACE PART
int[] faceOutline = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
int[] leftEyebrow = {17, 18, 19, 20, 21};
int[] rightEyebrow = {22, 23, 24, 25, 26};
int[] nosePart1 = {27, 28, 29, 30};
int[] nosePart2 = {31, 32, 33, 34, 35};
int[] leftEye = {36, 37, 38, 39, 40, 41, 36};
int[] leftEye_close = {36,39,40,41};
int[] rightEye = {42, 43, 44, 45, 46, 47, 42};
int[] rightEye_close = {42,45,46,47};
int[] mouthPart1 = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 48};
int[] mouthPart2 = {60, 61, 62};
int[] mouthPart3 = {62,63};
int[] mouthPart4 = {63, 64, 65};
int[] mouthPart5 = {60, 65};
//Distant Calculation
//Right EYE//int[] leftEye = {36, 37, 38, 39, 40, 41, 36}; 36 is far right, not the eye's head
//eyeR_w = dist((meshPoints[39].x*factor)-factor_x, meshPoints[39].y*factor, (meshPoints[36].x*factor)-factor_x, meshPoints[36].y*factor);
//Left EYE//int[] rightEye = {42, 43, 44, 45, 46, 47, 42}; //42 is the eye's head.
//eyeL_w = dist((meshPoints[42].x*factor)-factor_x, meshPoints[42].y*factor, (meshPoints[45].x*factor)-factor_x, meshPoints[45].y*factor);
void initMesh() {
// initialize meshPoints array with PVectors
meshPoints = new PVector[66];
for (int i = 0; i < meshPoints.length; i++) {
meshPoints[i] = new PVector();
}
}
// this method was generated programmatically. It's fugly.
public void loadMesh(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float x5, float y5, float x6, float y6, float x7, float y7, float x8, float y8, float x9, float y9, float x10, float y10, float x11, float y11, float x12, float y12, float x13, float y13, float x14, float y14, float x15, float y15, float x16, float y16, float x17, float y17, float x18, float y18, float x19, float y19, float x20, float y20, float x21, float y21, float x22, float y22, float x23, float y23, float x24, float y24, float x25, float y25, float x26, float y26, float x27, float y27, float x28, float y28, float x29, float y29, float x30, float y30, float x31, float y31, float x32, float y32, float x33, float y33, float x34, float y34, float x35, float y35, float x36, float y36, float x37, float y37, float x38, float y38, float x39, float y39, float x40, float y40, float x41, float y41, float x42, float y42, float x43, float y43, float x44, float y44, float x45, float y45, float x46, float y46, float x47, float y47, float x48, float y48, float x49, float y49, float x50, float y50, float x51, float y51, float x52, float y52, float x53, float y53, float x54, float y54, float x55, float y55, float x56, float y56, float x57, float y57, float x58, float y58, float x59, float y59, float x60, float y60, float x61, float y61, float x62, float y62, float x63, float y63, float x64, float y64, float x65, float y65) {
//println("loading mesh...");
meshPoints[0].x = x0;
meshPoints[0].y = y0;
meshPoints[1].x = x1;
meshPoints[1].y = y1;
meshPoints[2].x = x2;
meshPoints[2].y = y2;
meshPoints[3].x = x3;
meshPoints[3].y = y3;
meshPoints[4].x = x4;
meshPoints[4].y = y4;
meshPoints[5].x = x5;
meshPoints[5].y = y5;
meshPoints[6].x = x6;
meshPoints[6].y = y6;
meshPoints[7].x = x7;
meshPoints[7].y = y7;
meshPoints[8].x = x8;
meshPoints[8].y = y8;
meshPoints[9].x = x9;
meshPoints[9].y = y9;
meshPoints[10].x = x10;
meshPoints[10].y = y10;
meshPoints[11].x = x11;
meshPoints[11].y = y11;
meshPoints[12].x = x12;
meshPoints[12].y = y12;
meshPoints[13].x = x13;
meshPoints[13].y = y13;
meshPoints[14].x = x14;
meshPoints[14].y = y14;
meshPoints[15].x = x15;
meshPoints[15].y = y15;
meshPoints[16].x = x16;
meshPoints[16].y = y16;
meshPoints[17].x = x17;
meshPoints[17].y = y17;
meshPoints[18].x = x18;
meshPoints[18].y = y18;
meshPoints[19].x = x19;
meshPoints[19].y = y19;
meshPoints[20].x = x20;
meshPoints[20].y = y20;
meshPoints[21].x = x21;
meshPoints[21].y = y21;
meshPoints[22].x = x22;
meshPoints[22].y = y22;
meshPoints[23].x = x23;
meshPoints[23].y = y23;
meshPoints[24].x = x24;
meshPoints[24].y = y24;
meshPoints[25].x = x25;
meshPoints[25].y = y25;
meshPoints[26].x = x26;
meshPoints[26].y = y26;
meshPoints[27].x = x27;
meshPoints[27].y = y27;
meshPoints[28].x = x28;
meshPoints[28].y = y28;
meshPoints[29].x = x29;
meshPoints[29].y = y29;
meshPoints[30].x = x30;
meshPoints[30].y = y30;
meshPoints[31].x = x31;
meshPoints[31].y = y31;
meshPoints[32].x = x32;
meshPoints[32].y = y32;
meshPoints[33].x = x33;
meshPoints[33].y = y33;
meshPoints[34].x = x34;
meshPoints[34].y = y34;
meshPoints[35].x = x35;
meshPoints[35].y = y35;
meshPoints[36].x = x36;
meshPoints[36].y = y36;
meshPoints[37].x = x37;
meshPoints[37].y = y37;
meshPoints[38].x = x38;
meshPoints[38].y = y38;
meshPoints[39].x = x39;
meshPoints[39].y = y39;
meshPoints[40].x = x40;
meshPoints[40].y = y40;
meshPoints[41].x = x41;
meshPoints[41].y = y41;
meshPoints[42].x = x42;
meshPoints[42].y = y42;
meshPoints[43].x = x43;
meshPoints[43].y = y43;
meshPoints[44].x = x44;
meshPoints[44].y = y44;
meshPoints[45].x = x45;
meshPoints[45].y = y45;
meshPoints[46].x = x46;
meshPoints[46].y = y46;
meshPoints[47].x = x47;
meshPoints[47].y = y47;
meshPoints[48].x = x48;
meshPoints[48].y = y48;
meshPoints[49].x = x49;
meshPoints[49].y = y49;
meshPoints[50].x = x50;
meshPoints[50].y = y50;
meshPoints[51].x = x51;
meshPoints[51].y = y51;
meshPoints[52].x = x52;
meshPoints[52].y = y52;
meshPoints[53].x = x53;
meshPoints[53].y = y53;
meshPoints[54].x = x54;
meshPoints[54].y = y54;
meshPoints[55].x = x55;
meshPoints[55].y = y55;
meshPoints[56].x = x56;
meshPoints[56].y = y56;
meshPoints[57].x = x57;
meshPoints[57].y = y57;
meshPoints[58].x = x58;
meshPoints[58].y = y58;
meshPoints[59].x = x59;
meshPoints[59].y = y59;
meshPoints[60].x = x60;
meshPoints[60].y = y60;
meshPoints[61].x = x61;
meshPoints[61].y = y61;
meshPoints[62].x = x62;
meshPoints[62].y = y62;
meshPoints[63].x = x63;
meshPoints[63].y = y63;
meshPoints[64].x = x64;
meshPoints[64].y = y64;
meshPoints[65].x = x65;
meshPoints[65].y = y65;
}
float area =0.2;
float ori = 0.01;
void comparison() {
if (eyeLeftHeight != 0.0&& plugged) {
//println("comparing");
//reportFrame();
videoFrame++;
if (videoFrame<f) {//frameCount
TableRow row = referTable.getRow(videoFrame); //sync to the referTable it was frameCount
NKframe = row.getInt("frameCount");
NKBrowL = row.getFloat("LBrowH");
NKBrowR = row.getFloat("RBrowH");
NKEyeL = row.getFloat("LEyeH");
NKEyeR = row.getFloat("REyeH");
NKNose = row.getFloat("nose");
NKMouthH = row.getFloat("MouseH");
NKMouthW = row.getFloat("MouseW");
NKOriX = row.getFloat("OriX");
NKOriY = row.getFloat("OriY");
NKOriZ = row.getFloat("OriZ");
}
//scoring();
if (endOfClip) { //frameCount >=90 //endOfClip
//scoring();
frameCount =0;
videoFrame = 0;
// score = 0;
//println("show the SCORE HERE");
// endOfClip = false;
} else {
scoring();
}
} else {
frameCount =0;
videoFrame=0;
//score = 0;
}
}
void scoring() {
/*println("FRAME : " + NKframe+ " CSV : "+NKOriZ +
" left : "+poseOrt_z*-1 + " SCORE : "+score);*/ //" right : "+rightEyebrowHeight +
if (NKBrowL-area <rightEyebrowHeight && NKBrowL+area >rightEyebrowHeight) {
score++;
}
if (NKBrowR-area<leftEyebrowHeight && NKBrowR+area >leftEyebrowHeight) {
score++;
}
if (NKEyeL-area< eyeRightHeight && NKEyeL+area> eyeRightHeight) {
score++;
}
if (NKEyeR-area< eyeLeftHeight && NKEyeR+area >eyeLeftHeight ) {
score++;
}
if (NKNose-area< nostrilHeight && NKNose+area >nostrilHeight) {
score++;
}
if (NKMouthH-area< mouthHeight && NKMouthH+area> mouthHeight) {
score++;
}
if (NKMouthW-area< mouthWidth && NKMouthW+area> mouthWidth) {
score++;
}
if (NKOriX-ori<poseOrt_x && NKOriX+ori>poseOrt_x) {
score++;
}
if (NKOriY-ori<poseOrt_y && NKOriY+ori>poseOrt_y) {
score++;
}
if (NKOriZ-ori<poseOrt_z*-1 && NKOriZ+ori>poseOrt_z*-1) {
score++;
}
//score=round((score*100)/max);
displayScore();
}
int scoreP;
void displayScore(){
scoreP=round(score*100)/max;
if (scoreP <= 9) {
scoreString = "You are such a mundane person.";
} else if (scoreP>=10 && scoreP<=39) {
scoreString = "Your acting is ok but still too boring.";
} else if ( scoreP>=40 & scoreP <=59) {
scoreString = "You are kidda fancy person.";
} else if ( scoreP>=60 & scoreP <=79) {
scoreString = "Wow!! May be you can be a star one day.";
} else if ( scoreP>=80 & scoreP <=99 ) {
scoreString = "OH YEAH, BABY!! Ready for a spotlight?!";
} else if (scoreP>=100){
scoreString = "No wonder who is the next celebrity of the year";
}
}
void loadReferTable() {
//referTable = loadTable("NikkiVideoData.csv","header");
//println(referTable.getRowCount() + "total rows in table");
for (TableRow row : referTable.rows()) {
NKframe = row.getInt("frameCount");
NKBrowL = row.getFloat("LBrowH");
NKBrowR = row.getFloat("RBrowH");
NKEyeL = row.getFloat("LEyeH");
NKEyeR = row.getFloat("REyeH");
NKNose = row.getFloat("nose");
NKMouthH = row.getFloat("MouseH");
NKMouthW = row.getFloat("MouseW");
NKOriX = row.getFloat("OriX");
NKOriY = row.getFloat("OriY");
NKOriZ = row.getFloat("OriZ");
println("DATA FROM THE CSV : "+NKOriZ);
}
}
void saveReferTable() {
infoTable = new Table();
infoTable.addColumn("frameCount");
infoTable.addColumn("LBrowH");
infoTable.addColumn("RBrowH");
infoTable.addColumn("LEyeH");
infoTable.addColumn("REyeH");
infoTable.addColumn("nose");
infoTable.addColumn("MouseH");
infoTable.addColumn("MouseW");
infoTable.addColumn("OriX");
infoTable.addColumn("OriY");
infoTable.addColumn("OriZ");
//saveTable(infoTable, "table.csv");
//////////////////these were at setup()/////////////////////////
TableRow newRow = infoTable.addRow();
newRow.setInt("frameCount", frameCount);//infoTable.lastRowIndex());
newRow.setFloat("LBrowH", Math.round(leftEyebrowHeight*100)/100.0);
newRow.setFloat("RBrowH", Math.round(rightEyebrowHeight*100)/100.0);
newRow.setFloat("LEyeH", Math.round(eyeLeftHeight*100)/100.0);
newRow.setFloat("REyeH", Math.round(eyeRightHeight*100)/100.0);
newRow.setFloat("nose", Math.round(nostrilHeight*100)/100.0);
newRow.setFloat("MouseH", Math.round(mouthHeight*100)/100.0);
newRow.setFloat("MouseW", Math.round(mouthWidth*100)/100.0);
newRow.setFloat("OriX", Math.round(poseOrt_x*100)/100.0);
newRow.setFloat("OriY", Math.round(poseOrt_y*1000)/1000.0);
newRow.setFloat("OriZ", Math.round(poseOrt_z*100)/100.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.