Theory.

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
import processing.video.*;
import blobDetection.*;

Minim minim;
Capture cam;
BlobDetection theBlobDetection;
float rot =0.0;

PImage img;
boolean newFrame=false;
PImage images[];
PImage images2[];
int f;

AudioPlayer song;

// ==================================================

void setup()
{
size(1000, 1000,P3D);
smooth();
cam = new Capture(this, 40*4, 30*4);

cam.start();
img = new PImage(80,60);
theBlobDetection = new BlobDetection(img.width, img.height);
theBlobDetection.setPosDiscrimination(true);
theBlobDetection.setThreshold(0.2f);
imageBank(“a”,16);
//imageVank(“b”,16);

minim = new Minim(this);
song = minim.loadFile(“Pearl.mp3”);
song.play();
}

void captureEvent(Capture cam)
{
tint(0,0,0);
cam.read();
newFrame = true;
}

// ==================================================
// draw()
// ==================================================
void draw()
{

if (f<images.length) {

image(images[f],100,100);
f=f+1;
delay(50);
}
if (f == 16) {
f=1;
}

//====================================
{
newFrame=false;
image(cam, 0, 0, width, height);

img.copy(cam, 0, 0, cam.width, cam.height,
0, 0, img.width, img.height);

theBlobDetection.computeBlobs(img.pixels);
drawBlobsAndEdges(true, true);
}

}

// ==================================================

void imageBank(String index, int filecount) {
images= new PImage[filecount];
images2= new PImage[filecount];
for ( int i = 0; i< images.length; i++ ) {
images[i] = loadImage(index + (i+1) + “.jpg” );
images2[i] = loadImage(index + (i/1) + “.jpg” );

}

}
//—————————————————————————–
void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges)
{

noTint();
Blob b;
EdgeVertex eA, eB;
for (int n=0; n<theBlobDetection.getBlobNb(); n++)
{

b=theBlobDetection.getBlob(n);
if (b!=null)
{
if (drawEdges)
{

for (int m=0; m<b.getEdgeNb(); m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)

image(
images2[f],
eB.x*width, eB.y*height
);

}

}
if (drawBlobs)
{
image(
images[f],
b.xMin*width, b.yMin*height);

}
}
}
for (int n=0; n<theBlobDetection.getBlobNb(); n++)
{

//translate(mouseX,mouseY);
translate(-129,-39.0,0);
rotateY(60+rot/height);

//rotateZ(25+rot);
//rotateX(10+rot/width);

b=theBlobDetection.getBlob(n);
if (b!=null)
{
if (drawEdges)
{

for (int m=0; m<b.getEdgeNb(); m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)

image(
images[f],
eB.x*width, eB.y*height
);

}

}
if (drawBlobs)
{
image(
images[f],
b.xMin*width, b.yMin*height);

}
}
rot +=0.9;
}
for (int n=0; n<theBlobDetection.getBlobNb(); n++)
{
translate(-129,-39.0,0);
rotateX(60+rot/height);

b=theBlobDetection.getBlob(n);
if (b!=null)
{
if (drawEdges)
{

for (int m=0; m<b.getEdgeNb(); m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)

image(
images[f],
eB.x*width, eB.y*height
);

}

}
if (drawBlobs)
{
image(
images[f],
b.xMin*width, b.yMin*height);

}
}
rot +=0.9;
}
for (int n=0; n<theBlobDetection.getBlobNb(); n++)
{
translate(-129,-39.0,0);
rotateZ(60+rot/height);

b=theBlobDetection.getBlob(n);
if (b!=null)
{
if (drawEdges)
{

for (int m=0; m<b.getEdgeNb(); m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)

image(
images[f],
eB.x*width, eB.y*height
);

}

}
if (drawBlobs)
{
image(
images[f],
b.xMin*width, b.yMin*height);

}
}
rot +=0.9;
}
}

Advertisements
This entry was posted in Timebased and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s