Motion Detection Changing an Aspect Ration

I have a code of a vibrating rectangle with a video captured by the webcam. As you play with the mouse, the aspect ratio changes. I was wondering how to do it so when there is motion or a change in position detected by the camera, the aspect ration changes
below is my code

float x, y; // X and Y coordinates of text
PImage img;
int direction = 1;
float signal;
float spacer = 23.2;
import processing.video.*;

Capture video;

void setup() {
  fullScreen();
  noFill();
  background(#000000);
  stroke(255);
  frameRate(30);
  noStroke();
  x = width / 2;
  y = height / 2;
  video = new Capture(this, 320, 240); 
  video.start();
   noCursor();
}

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

void draw() {
  fill(random(10));
  rect(0, 0, width, height);
 
  fill(#FFFFFF);
  tint(mouseX, mouseY, random(1000));  
  translate(width/2, height/2);  
  
  if (x<0) {
    x = 10;
  }
  if (y<0) {
    y = 10;
  }
  if (x>width) {
    x = width*2;
  }
  if (y>height) {
    y = height*2;
  }
  
  imageMode(CENTER);  
  rotate(PI/20);  
  image(video, random(100), random(100), mouseX, mouseY);
}
1 Like

Welcome to the forum!
To help people help you, please format your code with </> button or ``` before and after.

For that you can use openCV, BoofCV, or BlobDetection libraries to do blob detection or object tracking. Most of the video and vision libraries in PDE Contributions Manager are listed here: