33
edits
Changes
→Documentation
Images coming soon.
<nowiki>
import hypermedia.video.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.signals.*;
Minim minim;
AudioInput in;
OpenCV opencv;
// contrast/brightness values
int contrast_value = 0;
int brightness_value = 0;
float loudestFreqAmp = 0;
float loudestFreq = 0;
int timerCounter = 0;
void setup()
{
size(640, 480, P2D);
frameRate(30);
noCursor();
minim = new Minim(this);
minim.debugOn();
background(255);
noStroke();
// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 1024);
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"
}
void draw()
{
// grab a new frame
// and convert to gray
opencv.read();
opencv.convert( GRAY );
opencv.contrast( contrast_value );
opencv.brightness( brightness_value );
// proceed detection
java.awt.Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );
// display the image
//image( opencv.image(), 0, 0 );
// draw face area(s)
// noFill();
// stroke(255,0,0);
// for( int i=0; i<faces.length; i++ ) {
// rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
// }
int posX = 0;
int posY = 0;
for( int i=0; i<faces.length; i++ ) {
posX = faces[i].x;
posY = faces[i].y;
}
float m = 0;
for(int i = 0; i < in.bufferSize() - 1; i++) {
if ( abs(in.mix.get(i)) > m ) {
m = abs(in.mix.get(i));
System.out.println(in.mix.get(i));
}
}
m*=150;
drawCircles(posX, posY, m, 10);
if(timerCounter >= 20)
{
background(255);
timerCounter = 0;
}
timerCounter++;
}
void keyPressed() {
if (key == 'a') {
background(255);
}
}
// Circle splatter machine
void drawCircles(float x, float y, float radius, int level)
{
noStroke();
float tt = 200 * level / 6.0;
fill (tt, 0, 116);//tt, 0, 116
ellipse(x, y, radius*2, radius*2);
if (level > 1) {
level = level - 1;
int num = int (random(2, 5));
for(int i=0; i<num; i++) {
float a = random(0, TWO_PI);
float nx = x + cos(a) * 6.0 * level;
float ny = y + sin(a) * 6.0 * level;
drawCircles(nx, ny, radius/2, level);
}
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
</nowiki>