Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to change color of overlapping ellipses

$
0
0

Hi! I have a question. I am fairly new to processing, so I need a little help.

I am trying to track the visitors of an exhibition. Right now I am comparing each frame with the previous one, detecting changes in pixels. Each change is visualized with an ellipse with opacity 10. The overlapping ellipses create a darker area, of course, but I would like to have the color of the ellipses (or overlaps of the ellipses) change when they have overlapped a few times (let's say 10). I would like to have a heat map effect.

This is my code right now:

import processing.video.*;
Capture video;

float threshold = 30;
int vidw = 640;// video width zie lijst println
int vidh = 420;// video height
int step = 2; //om de hoeveel pixels scannen op beweging
PImage prevFrame;



void setup() {
  size(displayWidth, displayHeight);//P3D
  //video = new Capture(this, "name=Logitech HD Pro Webcam C920,size=640x480,fps=30");
  video = new Capture(this, 640, 420);
  video.start();
  noCursor();
  prevFrame = createImage(vidw, vidh, RGB);
  //frameRate(12);
  smooth();
  noStroke();
  background (#FFFFFF);
}

void captureEvent(Capture video) {
  prevFrame.copy(video, 0, 0, vidw, vidh, 0, 0, vidw, vidh); // Before we read the new frame, we always save the previous frame for comparison!
  prevFrame.updatePixels();  // Read image from the camera
  video.read();
}


void draw() {
  //background (0);
  //image(video, 0, 0, width, height);
  //println(vidw + " - " + vidh);
  //if (millis()>2000) {
  coordinates();
  //}
}


void coordinates() {
  loadPixels();
  video.loadPixels();
  prevFrame.loadPixels();
  // Begin loop to walk through every pixel
  for (int i = 0; i < vidw; i +=step ) {
    for (int j = 0; j < vidh; j +=step) {
      int loc = i + j*vidw;                   // Step 1, what is the 1D pixel location
      color current = video.pixels[loc];      // Step 2, what is the current color
      color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color
      float r1 = red(current);
      float g1 = green(current);
      float b1 = blue(current);
      float r2 = red(previous);
      float g2 = green(previous);
      float b2 = blue(previous);
      float diff = dist(r1, g1, b1, r2, g2, b2);
      if (diff > threshold) {
        fill(#5882FA, 10);
        ellipse(i*step,j*step,10,10);
        }
    }
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles