import processing.core.*; 
import processing.xml.*; 

import hypermedia.video.*; 

import java.applet.*; 
import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 
import java.util.regex.*; 

public class mind_reader extends PApplet {



OpenCV opencv;

int contrast_value    = 0;
int brightness_value  = 0;

PImage hotdude;
PFont font;

int MODE = 0;

public void setup() {
  size(640, 480);

  opencv = new OpenCV( this );
  opencv.capture( width, height );                   // open video stream
  opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );  // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"

  stroke(200, 200, 200);
  strokeWeight(2.0f);
  fill(255);

  font = createFont("FFScala", 32);
  hotdude = loadImage("HotGuy2.png");

  textFont(font);   
}


public void stop() {
  opencv.stop();
  super.stop();
}

public void draw() {  
  opencv.read();
  image(opencv.image(), 0, 0);

  Rectangle[] faces = opencv.detect( 1.2f, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

  for(int i=0; i<faces.length; i++) {
    float x = faces[i].x;
    float y = faces[i].y;    
    fill(255);
    //rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height ); 
    ellipse(x, y, 10, 10);
    ellipse(x-18, y-8, 18, 18);
    ellipse(x-40, y-30, 27, 27);
    if (MODE == 0) {
      ellipse(x-20, y-90, 200, 70);
      fill(0);
      text("I <3 dudes", x-98, y-80);         
    } 
    else if (MODE == 1) {
      ellipse(x-100, y-150, 200, 200);
      image(hotdude, x-160, y-223, 120, 150);
    }          
  }
  if(frameCount % 30 == 0) changeMode();
  loadPixels();
  
}

public void changeMode() {
  MODE += 1;
  if(MODE > 1) {
    MODE = 0;  
  }
}


  static public void main(String args[]) {
    PApplet.main(new String[] { "--bgcolor=#c0c0c0", "mind_reader" });
  }
}

