I'm trying to write a piece of code that uses the flob library to detect the movement of a person though a webcam. The motion detection captured interacts with random shapes that appear on the screen. When the shapes are "touched" they disappear and re-spawn off-screen as one of 8 random shapes through my changeShape function. I know where it's currently placed the shapes will continuously changeShapes. Can anyone tell me if I'm doing something wrong? Or guide me in the write direction to fixing this code?
video = new Capture(this, 320, 240); video.start();
// create one image with the dimensions you want flob to run at videoinput = createImage(videoResolution, videoResolution, RGB);
// construct flob flob = new Flob(this, videoResolution, videoResolution, width, height); //Not exactly sure what this does, but it's needed flob.setThresh(10); //Sensitivity - Default 45 flob.setFade(80); flob.setMinNumPixels(10);
objects = new Object[100]; for (int i=0; i < objects.length; i++) { objects[i] = new Object(); }
}
void draw() { background(0);
if (video.available()) { if (!omset) { if (om) flob.setOm(flob.CONTINUOUS_DIFFERENCE); else flob.setOm(flob.STATIC_DIFFERENCE); omset=true; } video.read();
//downscale video image to videoinput pimage videoinput.copy(video, 0, 0, 320, 240, 0, 0, videoResolution, videoResolution); // Here is defined the method of calculation: calc, calcsimple, ou tracksimple // Tracksimple is more accurate, but is much more data intensive than calcsimple // flob.tracksimple( flob.binarize(video) ); flob.calcsimple( flob.binarize(videoinput) ); }
//Displays the actual webcam stream image(flob.getSrcImage(), 0, 0, width, height);
// collision float collisionData[] = new float[5]; for (int i=0;i<objects.length;i++) { float x = objects[i].x / (float) width; float y = objects[i].y / (float) height; collisionData = flob.imageblobs.postcollidetrackedblobs(x, y, objects[i].radius/(float)width); if (collisionData[0] > 0) { objects[i].collision=true;
I am currently writing a motion detection code that "pops" bubbles when they come into contact with a person.
I'm trying to make this code more interesting by having the bubbles become multiple different objects once they reappear off screen (once a bubble is "popped", it's x and y coordinates are randomly moved to allow for a continuous game). I was wondering if there was an easy way to have the bubbles become different shapes randomly?
This is what I've come up with, but I'm receiving a "cannot convert from int to Boolean" error.
void changeShape() { int shape = int(random(1, 6)); if (shape = 1) { rect(x, y, radius*2, radius*2); } if (shape = 2) { triangle(x+30, y+75, x+58, y+20, x+86, y+75); } if (shape = 3) { ellipse(x, y, radius*2, radius*2); } if (shape = 4) { fill(random(255), 0, 0, 128); rect(x, y, radius*2, radius*2); } if (shape = 5) { fill(0, random(255), 0, 128); triangle(x+30, y+75, x+58, y+20, x+86, y+75); } if (shape = 6) { fill(0, 0, random(255), 128); ellipse(x, y, radius*2, radius*2); } }
This is my first semester learning processing, and clearly, I'm no expert. I have a final presentation in which I'm supposed to
create an interactive display at an Art Exhibit. I'm attempting to use the flob library to detect movement on a webcam and use that movement to interact with the balls bouncing around on the screen. The collision part of the code is working, but I'm not content with just that. Not only is the image pixelated but it's also pretty bland.
So I set up an array function to create a purple trace of the movements detected by the webcam, and I'm trying to overlay this capture on top of the pixelated one.
Hoping for some answers, because I cannot for the life of me get this to cooperate.
balls = new Ball[max_balls]; for (int i=0; i < balls.length; i++) { balls[i] = new Ball(); } }
void draw() { background(0);
if (video.available() == true) { if (!omset) { if (om) flob.setOm(flob.CONTINUOUS_DIFFERENCE); else flob.setOm(flob.STATIC_DIFFERENCE); omset=true; } video.read();
int index; int pixelsPerCol = videoWidth / videoColumns; int pixelsPerRow = videoHeight / videoRows;
image (video, 0, 0);
// 'activity' array set to zero for (int i=0; i < activity.length; i++) { activity[i] = 0; }
// For each pixel in the video frame for (int i=0; i < video.pixels.length; i++) { // x and y Position calculate the quadrant int x = (int) ((i % video.width) / pixelsPerCol); int y = (int) ((i / video.width) / pixelsPerRow); // Quadrant membership of the pixel to find out. // Later important for the 'activity' array. index = y * videoColumns + x; // Color at position 'i' in the camera image color col = video.pixels[i]; // The sum of all three color channels float sum = red (col) + green (col) + blue (col); // Change the pixel color value calculated based on all images float deltaPixel = (buffer1[i] + buffer2[i] + buffer3[i]) / 3 - sum; if (deltaPixel < 0) { deltaPixel *= -1; } // Add the change to the total value of the quadrant activity[index] += deltaPixel; // Move the 'image memory' a step backwards. buffer3[i] = buffer2[i]; buffer2[i] = buffer1[i]; buffer1[i] = sum; }
for (int i=0; i < activity.length; i++) {
// Calculate average color value change by dividing the sum by the number of pixels activity[i] /= pixelsPerCol * pixelsPerRow; if (activity[i]>=255) // println(i);
// Drawing of quadrants on the display stroke (0, 0); // Changes the color of the movement displayed fill (150, 50, 250, activity[i]); rect ((i % videoColumns) * pixelsPerCol, (i / videoColumns) * pixelsPerRow, pixelsPerCol, pixelsPerRow); }
//downscale video image to videoinput pimage // tint(255, 0); ---- End goal is to have this be hidden videoinput.copy(video, 0, 0, 320, 240, 0, 0, videoResolution, videoResolution); // Here is defined the method of calculation: calc, calcsimple, or tracksimple // Tracksimple is more accurate, but is much more data intensive than calcsimple // flob.tracksimple( flob.binarize(video) ); flob.calcsimple( flob.binarize(videoinput) ); }
//Displays the actual webcam stream image(flob.getSrcImage(), 0, 0, width, height);
// collision float collisionData[] = new float[5]; for (int i = 0; i<balls.length; i++) { float x = balls[i].x / (float) width; float y = balls[i].y / (float) height; collisionData = flob.imageblobs.postcollidetrackedblobs(x, y, balls[i].radius/(float)width); if (collisionData[0] > 0) { balls[i].collision = true; balls[i].xSpeed += collisionData[1] * width * 0.015; balls[i].ySpeed += collisionData[2] * height * 0.015; //balls[i].radius = 0; } else { balls[i].collision = false; } balls[i].run(); } }
void keyPressed() { if (key=='o') { om^=true; omset=false; } }