# Width (0) and height (0) cannot be \<= 0

**URL:** https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459
**Category:** Libraries
**Created:** [November 11, 2018, 9:43pm UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459 "2018-11-11T21:43:37Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![ProcessingSuzanne](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@ProcessingSuzanne](https://discourse.processing.org/u/ProcessingSuzanne)
#### Post date: [November 11, 2018, 9:43pm UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/1 "2018-11-11T21:43:37Z")

</div>

I am working on a very simple BackgroundSubtraction code on processing. In the beginning everything was woking fine but now I get the “Width (0) and height (0) cannot be \<= 0” error every time I try to play the code. Here is my code:

```auto
import gab.opencv.*;
import processing.video.*;

Movie video;
OpenCV opencv;

void setup() {
  size(1920,1080);
  video = new Movie(this, "Rotatie.mov");
  opencv = new OpenCV(this, 1920,1080);
  
  opencv.startBackgroundSubtraction(5, 3, 0.5);
  
  video.loop();
  video.play();
  background(255);
}

void draw() {
  //background(255);
  //scale(2);

// image(video, 0, 0);  
  opencv.loadImage(video);
  
  opencv.updateBackground();
  
  opencv.dilate();
  opencv.erode();

  
  noFill();
  stroke(122, 179, 216);
  strokeWeight(0.5);
  //noStroke();
  for (Contour contour : opencv.findContours()) {
    //float fil = map(contour.getPoints().size(),0,1000,0,255);
    //fill(0,150);
    contour.draw();
    
     //fill(0,10);
    //contour.getConvexHull().draw();
    
    
      //fill(0,10);
    //contour.getPolygonApproximation().draw();
  }
   
  }

void movieEvent(Movie m) {
  m.read();
  
  //saveFrame("output1.1/standpunt_####.png"); 
}

```

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [November 11, 2018, 10:31pm UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/2 "2018-11-11T22:31:52Z")

</div>

Hey,

Please format your code by pressing `Ctrl+T` in the Processing IDE code editor and insert it by pressing `<\>` in the message editor.

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [November 11, 2018, 10:34pm UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/3 "2018-11-11T22:34:08Z")

</div>

What line gives you the error?  
We don’t have your resources so we won’t be able to reproduce the error.  
Also, you need to format your code.

Kf

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [November 11, 2018, 10:47pm UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/4 "2018-11-11T22:47:00Z")

</div>

> [@Problem with slitscan effect for pre-recorded video](https://discourse.processing.org/t/problem-with-slitscan-effect-for-pre-recorded-video/5456/2):
>
> The video library takes some time to “ignite” after we issue a “play” command. Until then, its width & height dimensions are still 0! As a workaround, we can delay() inside setup() until the video is fully ready. This way, when draw() is called back for the 1st time, we’re safe to access the video. void setup() { // ... ( myMovie = new Movie(this, "kat.mov") ).loop(); while (myMovie.height == 0) delay(2); }

---

<div class="post-metadata">

### Author: ![ProcessingSuzanne](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@ProcessingSuzanne](https://discourse.processing.org/u/ProcessingSuzanne)
#### Post date: [November 12, 2018, 7:50am UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/6 "2018-11-12T07:50:22Z")

</div>

`opencv.loadImage(video);`

This line gives the error. Here is also the sketch folder from my file. The videos I’m using are in the data folder.

 ![Schermopname%20(99)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a1612436b5750de61de7aeee91e2c7935e02bee8.png)

---

<div class="post-metadata">

### Author: ![ProcessingSuzanne](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@ProcessingSuzanne](https://discourse.processing.org/u/ProcessingSuzanne)
#### Post date: [November 12, 2018, 7:50am UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/7 "2018-11-12T07:50:56Z")

</div>

Thank you! How exactly do I put this in my script?I am very new to processing! I have tried it like this:

```auto
void setup() {
  size(960,540);
  video = new Movie(this,"Rotatie.mov").loop();
  while (myMovie.height==0) delay(2);

```

But then it gives me the error: “cannot convert from void to Movie”.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [November 12, 2018, 8:02am UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/8 "2018-11-12T08:02:40Z")

</div>

> [@ProcessingSuzanne](#):
>
> How exactly do I put this in my script?

It’s pretty obviously _video_ is the variable holding the Movie object in your own sketch! 🙄

```java
import gab.opencv.OpenCV;
import processing.video.Movie;

OpenCV opencv;
Movie video;

void setup() {
  size(960, 540);

  noFill();
  stroke(122, 179, 216);
  strokeWeight(.5);

  opencv = new OpenCV(this, width, height);
  opencv.startBackgroundSubtraction(5, 3, .5);

  ( video = new Movie(this, "Rotatie.mov") ).loop();
  while (video.height == 0) delay(2);
}

void movieEvent(final Movie m) {
  m.read();
}

```

---

<div class="post-metadata">

### Author: ![ProcessingSuzanne](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@ProcessingSuzanne](https://discourse.processing.org/u/ProcessingSuzanne)
#### Post date: [November 12, 2018, 10:47am UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/9 "2018-11-12T10:47:18Z")

</div>

Now it gives me an error on line  
`video = new Movie(this, "Rotatie.mov").loop();`

the error says: “cannot convert from void to Movie”.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [November 12, 2018, 10:55am UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/10 "2018-11-12T10:55:34Z")

</div>

You have miscopied `( myMovie = new Movie(this, "kat.mov") ).loop();` from my link like this:  
`video = new Movie(this,"Rotatie.mov").loop();` 😷

And I’ve ended up following it in my answer post! 😑

It’s fixed in my post now: `( video = new Movie(this, "Rotatie.mov") ).loop();` 👷‍♂️

---

<div class="post-metadata">

### Author: ![ProcessingSuzanne](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@ProcessingSuzanne](https://discourse.processing.org/u/ProcessingSuzanne)
#### Post date: [November 12, 2018, 11:48am UTC](https://discourse.processing.org/t/width-0-and-height-0-cannot-be-0/5459/11 "2018-11-12T11:48:34Z")

</div>

It works! Thank you very much!
