Motion Detection
in
Core Library Questions
•
1 year ago
Hi I've been working on this sketch where the elements of the pattern change size based on the brightness of the video input. I want to change it so the pattern changes based on movement of the video input. So that I don't have to rely as much on lighting etc for the sketch to work properly.
Any help or pointers would be great.
Thanks
Sam
- import processing.video.*;
- final int VIDEO_WIDTH = 800;
- final int VIDEO_HEIGHT = 600;
- Capture video;
- int w = 20;
- Spot[][] sp;
- color[] c = new color[36];
- int cols = VIDEO_WIDTH / w;
- int rows = VIDEO_HEIGHT / w;
- void setup() {
- size(VIDEO_WIDTH, VIDEO_HEIGHT, P2D);
- smooth();
- //////Colours/////////
- c[0] = color(#f4b264);
- c[1] = color(#bee5e4);
- c[2] = color(#fe022b);
- c[3] = color(#082f56);
- c[4] = color(#f8f3d6);
- c[5] = color(#fceea7);
- c[6] = color(#ff7101);
- c[7] = color(#f1d7ca);
- c[8] = color(#ffafc3);
- c[9] = color(#abe6e2);
- c[10] = color(#e2e8ce);
- c[11] = color(#ffcb00);
- c[12] = color(#aae354);
- c[13] = color(#ddb0b7);
- c[14] = color(#d2e6b5);
- c[15] = color(#77a3be);
- c[16] = color(#005c9d);
- c[17] = color(#bb3325);
- c[18] = color(#fdd4e2);
- c[19] = color(#0dbbde);
- c[20] = color(#643324);
- c[21] = color(#99e1d3);
- c[22] = color(#ff92a9);
- c[23] = color(#a7bbba);
- c[24] = color(#d0e099);
- c[25] = color(#00b14b);
- c[26] = color(#0376b9);
- c[27] = color(#fedf2d);
- c[28] = color(#fbd362);
- c[29] = color(#fe5900);
- c[30] = color(#4fb900);
- c[31] = color(#fdd4e2);
- c[32] = color(#ddb0b7);
- c[33] = color(#a9998a);
- c[34] = color(#77a3be);
- c[35] = color(#bdb0b7);
- ///////////////////////
- sp = new Spot[cols][rows];
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- sp[i][j] = new Spot(i * w + (w/2), j * w + (w/2), w, c[int(random(0, 35))]);
- }
- }
- video = new Capture(this, cols, rows, 24);
- }
- void draw() {
- background(255);
- if (video.available()) {
- video.read();
- }
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- int x = i*w;
- int y = j*w;
- int loc = (video.width - i - 1) + j*video.width;
- color c = video.pixels[loc];
- float sz = (brightness(c)/255.0)*w;
- float csz = constrain(sz, 5, w);
- sp[i][j].display(csz);
- }
- }
- }
- //////////////////////////////////////////////////////////
- class Spot {
- // Variables
- float x;
- float y;
- float w;
- color c;
- // Constructor
- Spot(float xpos, float ypos, float wspot, color cspot) {
- x = xpos;
- y = ypos;
- w = wspot;
- c = cspot;
- }
- // Functions
- void display(float w) {
- fill(c);
- noStroke();
- ellipseMode(CENTER);
- ellipse(x, y, w, w);
- }
- }
1