82
edits
Changes
Blockman
,→Code
==Code==
import hypermedia.video.*;
import java.awt.Rectangle;
OpenCV opencv;
PFont font;
float ball_x;
float ball_y;
float ball_dir = 0;
float ball_size; // Radius
float dy = 0; // Direction
float dx = 0;
int dist_wall = 15;
int i;
//color c1 = color(102, 102, 0);
void setup() {
size(450, 450);
opencv = new OpenCV(this);
opencv.capture( width, height );
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load the FRONTALFACE description file
image( opencv.image(), 0, 0 ); // and display image
ellipseMode(RADIUS);
noStroke();
smooth();
ball_y = height/2;
ball_x = 1;
}
void draw() {
opencv.read();
image( opencv.image(), 0, 0 );
ball_x += dx;
ball_y += dy;
if(ball_x > width+ball_size) {
ball_x = -width/2 - ball_size;
ball_y = random(0, height);
dy = 0;
}
if (ball_x <= ball_size) ball_x=ball_size;
if (ball_x >= width-ball_size) ball_x=width-ball_size;
if (ball_y <= ball_size) ball_y=ball_size;
if (ball_y >= height-ball_size) ball_y=height-ball_size;
// detect anything ressembling a FRONTALFACE
Rectangle[] faces = opencv.detect();
// draw detected 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 );
ball_x = faces[i].x + (faces[i].width/2);
ball_y = faces[i].y + (faces[i].height/2);
ball_size = (faces[i].width/4) + (faces[i].height/4);
fill(0);
ellipse(ball_x, ball_y, ball_size, ball_size);
font = loadFont("Courier-20.vlw");
textFont(font);
text("CENSORED: TOO VULGAR", (ball_x-faces[i].height/2), (ball_y-faces[i].width/2));
fill(0);
}