how can i display an image with motion and colour detection?
in
Core Library Questions
•
6 months ago
Im trying to create an installation in which a web cam situated above the installation detects people at certain points of the exhibit and displays various graphics. Initially i had used a Shiffman motion detection (split into a 4x3 grid) sketch however when someone is still in the exhibit, the graphic would flicker or disappear all together.
For now, Ive adapted this sketch from shiffman's colour tracking so it compares with an image of the room instead of the previous pixel, but its still not right, can anyone help or provide a sketch that would allow me to do what im trying to achieve?
Thanks!
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 16-11: Simple color tracking
import processing.video.*;
// Variable for capture device
Capture video;
PImage room;
// A variable for the color we are searching for.
//color trackColor;
int node1x = 40;
int node1y = 40;
int radius = 40;
void setup() {
size(320,240);
video = new Capture(this,width,height,15);
// Start off tracking for red
// trackColor = color(255,0,0);
video.start();
smooth();
room = loadImage("room.png");
}
void draw() {
// Capture and display the video
if (video.available()) {
video.read();
}
video.loadPixels();
room.loadPixels();
image(video,0,0);
// Before we begin searching, the "world record" for closest color is set to a high number that is easy for the first pixel to beat.
float worldRecord = 1000;
// XY coordinate of closest color
int closestX = 0;
int closestY = 0;
// Begin loop to walk through every pixel
for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height; y ++ ) {
int loc = x + y*video.width;
// What is current color
color currentColor = video.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float b1 = blue(currentColor);
float r2 = red(room.pixels[loc]);
float g2 = green(room.pixels[loc]);
float b2 = blue(room.pixels[loc]);
// Using euclidean distance to compare colors
float d = dist(r1,g1,b1,r2,g2,b2); // We are using the dist( ) function to compare the current color with the color we are tracking.
// If current color is more similar to tracked color than
// closest color, save current location and current difference
if (d < worldRecord) {
worldRecord = d;
closestX = x;
closestY = y;
}
}
}
// We only consider the color found if its color distance is less than 10.
// This threshold of 10 is arbitrary and you can adjust this number depending on how accurate you require the tracking to be.
if (worldRecord < 5) {
// Draw a circle at the tracked pixel
fill(0);
strokeWeight(4.0);
stroke(0);
ellipse(closestX,closestY,16,16);
}
}
//void mousePressed() {
// // Save color where the mouse is clicked in trackColor variable
// int loc = mouseX + mouseY*video.width;
// trackColor = video.pixels[loc];
//}
1