: Listagem completa do código
import processing.video.*;
import processing.opengl.*;
import pFaceDetect.*;
MovieMaker mm;
//import JMyron.*;
BackgroundSubtraction bs = new BackgroundSubtraction(320, 240);
// o valor de threshold da subtraccao
int threshold = 10;
boolean showSubtraction = false;
//declarar
int alturaCara= 50;
int larguraCara = 50;
int larguraFerramentas = 200;
int alturaFerramentas = 200;
int larguraCaptura = 320;
int alturaCaptura= 240;
int cara_inicial = 0;
//PImage cara;
PImage caras [];
PImage cara_actual;
// detecÁ„o da cara
PFaceDetect face;
//webcam
import processing.video.*;
//JMyron myCapture;
boolean gravar = false;
void setup() {
size(1024, 768, OPENGL);
//frameRate(20);
face = new PFaceDetect(this,larguraCaptura, alturaCaptura, "haarcascade_frontalface_default.xml");
// myCapture = new JMyron();//make a new instance of the object
//myCapture.start(larguraCaptura, alturaCaptura);//start a capture at 320x240
caras = new PImage [10];
caras[0]=loadImage ("face_01.gif");
caras[1]=loadImage ("face_02.gif");
caras[2]=loadImage ("face_03.gif");
caras[3]=loadImage ("face_04.gif");
caras[4]=loadImage ("face_05.gif");
caras[5]=loadImage ("face_06.gif");
caras[6]=loadImage ("face_07.gif");
caras[7]=loadImage ("face_08.gif");
caras[8]=loadImage ("face_09.gif");
caras[9]=loadImage ("face_10.gif");
cara_actual = caras[0];
}
void draw() {
// background(0);
//myCapture.update ();
// actualizar a imagem da webcam
bs.update();
// subtrair o fundo
bs.subtract(threshold);
image (bs.pimage(), 0, 0, width, height);
face.findFaces(bs.pimage());
desenharFerramentas ();
desenhoCara ();
detectaFerramenta ();
showSubtraction();
println (frameRate);
if (gravar) {
mm.addFrame();
}
//public void mousePressed() {
//mm.finishMovie();
//}
}
void detectaFerramenta () {
// pedir a maior silhueta encontrada
Silhouette s = bs.getSilhouette(0);
if (s != null) {
s.setSize(width, height);
float[][]p = s.silhouette;
stroke(0, 0);
s.draw();
if (s.insideSilhouette (100, 200))
{
cara_actual = caras[0+cara_inicial] ;
}
if (s.insideSilhouette (300, 200))
{
cara_actual = caras[ 1 + cara_inicial];
}
if (s.insideSilhouette (500, 200))
{
cara_actual= caras[2 + cara_inicial];
}
if (s.insideSilhouette (700, 200))
{
cara_actual = caras[3 + cara_inicial];
}
if (s.insideSilhouette (900, 200))
{
cara_actual = caras[4 + cara_inicial];
}
}
}
void desenharFerramentas () {
int i;
for ( i = cara_inicial; i < cara_inicial+5; i = i + 1){
image (caras[i],larguraFerramentas*(i-cara_inicial) , 0, larguraFerramentas, alturaFerramentas);
}
if (frameCount % 100 == 0) {
cara_inicial= (cara_inicial + 1) % 6;
}
}
void desenhoCara () {
int [][] res = face.getFaces();
if (res.length>0) { // so desenhamos se foi encontrada pelo menos uma cara
int x = res[0][0];
int y = res[0][1];
int w = res[0][2];
int h = res[0][3];
image (cara_actual, x * width/larguraCaptura, y * height/alturaCaptura , w * width/larguraCaptura , h* height/alturaCaptura);
noFill ();
//rect (x * width/larguraCaptura, y * height/alturaCaptura , w * width/larguraCaptura , h* height/alturaCaptura);
// fill (255);
}
}
void showSubtraction() {
// para ajudar a ajustar a imagem
// se estiver ligado, mostramos a imagem de diferenca
if (showSubtraction) {
background(0);
PImage subtraction = new PImage(320, 240);
arraycopy(bs.subtraction, subtraction.pixels);
image(subtraction, 0, 0);
}
}
void keyPressed() {
if (key == ' ') {
bs.update();
bs.setBackgroundPixels(bs.image());
}
else if (key == 's') {
bs.settings();
}
else if (key == '+') {
threshold = threshold + 5;
println("Threshold: " + threshold);
}
else if (key == '-') {
threshold = threshold -5;
println("Threshold: " + threshold);
}
else if(key == 'd') {
showSubtraction = !showSubtraction;
println("Show subtraction: " + showSubtraction);
} else if (key =='m') {
gravar = !gravar;
if (gravar) {
mm = new MovieMaker(this,width,height,"p5test"+frameCount+".mov");//, MovieMaker.JPEG, MovieMaker.HIGH,30);
} else {
mm.finish();
}
}
}
Vídeo Arte Interactiva

sexta-feira, 13 de junho de 2008
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário