# Motion Detection Changing an Aspect Ration

**URL:** <https://discourse.processing.org/t/motion-detection-changing-an-aspect-ration/17826>\
**Category:** Libraries\
**Created:** [February 14, 2020, 7:47pm UTC](https://discourse.processing.org/t/motion-detection-changing-an-aspect-ration/17826 "2020-02-14T19:47:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiasocci](https://avatars.discourse-cdn.com/v4/letter/t/ecae2f/32.png) [@tiasocci](https://discourse.processing.org/u/tiasocci)\
**Post date:** [February 14, 2020, 7:47pm UTC](https://discourse.processing.org/t/motion-detection-changing-an-aspect-ration/17826/1 "2020-02-14T19:47:51Z")

</div>

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

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 17, 2020, 12:22am UTC](https://discourse.processing.org/t/motion-detection-changing-an-aspect-ration/17826/2 "2020-02-17T00:22:29Z")

</div>

Welcome to the forum!  
To help people help you, please [format your code](https://discourse.processing.org/faq#format-your-code) with \</\> button or ``` before and after.

> [@tiasocci](#):
>
> motion or a change in position detected by the camera

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:

> **[Libraries](https://processing.org/reference/libraries/#video&vision)**
>
> Extend Processing beyond graphics and images into audio, video, and communication with other devices.
