Motion Detection with Clusters

Hi there,

I’m trying to write code that will form a cluster of ellipses in the shape of a person as they approach the screen. I’m okay with the part of motion detection, but I can’t work out how to make the clusters appear and follow the movement. I can only make the ellipses one-by-one in a fixed position on the movement. Any help would be really appreciated

This is the code so far:

import gab.opencv.*;
import processing.video.*;
import java.awt.*;
PImage img1;

int val = 10;


Capture video;
OpenCV opencv;

void setup() {
  size(640, 480);
  background(0);
  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); 
  img1 = loadImage("Stephen.png");

  video.start();
}

void draw() {
  
  scale(2);
  opencv.loadImage(video);

image(video, 0, 0 );

  fill(255);
 stroke(0, 0, 0);
 strokeWeight(1);
  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i < faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    ellipse(faces[i].x+5, faces[i].y+0, 5, 5);
    ellipse(faces[i].x+10, faces[i].y+0, 5, 5);
    ellipse(faces[i].x+15, faces[i].y+0, 5, 5);
    ellipse(faces[i].x+33, faces[i].y+0, 5, 5);
    //the cluster would go here
  }
}

void captureEvent(Capture c) {
  c.read();
}

Do you know how to get the person’s silhouette? Without running your code – I see you doing face detection, so you know , but are you detecting the whole body? If you aren’t, then first you need to think about how you want to do that – with background subtraction, and/or a depth camera, and/or opencv etc.

It sounds like you want your faces[i] to be a target, and to create a group of shapes (or a particle system) that chase the target. You could use collision detection to have them push away from each other.

Alternately, you want your face bounding box to be a area that you fill with circles (e.g. using circle packing).