title: opencv error: assertion failed (size.width>0 && size.height>0) in unknown function line 261
body: <p>This is my code:</p>
  
  <pre><code>#include&lt;opencv\cv.h&gt;
  #include&lt;opencv\highgui.h&gt;
  using namespace cv;
  
  int main(){
      //create matrix to store image
      Mat image;
  
      //initialize capture    
      VideoCapture cap(0);
      cap.open(0);
  
      //create window to show image   
      namedWindow("window",1);
  
      while(1){   
          //copy webcam stream to image
          cap&gt;&gt;image;
  
          //print image to screen     
          imshow("window",image); //Error line
  
          //delay 33ms
          waitKey(33);
      }
  }
  </code></pre>
  
  <p>The error I get:</p>
  
  <pre><code>opencv error: assertion failed (size.width&gt;0 &amp;&amp; size.height&gt;0) in unknown function
  file...\opencv\modules\highgui\src\window.cpp line 261
  </code></pre>
  
  <p>In window.cpp, line 261 is: </p>
  
  <pre><code>CV_Assert(size.width&gt;0 &amp;&amp; size.height&gt;0);
  </code></pre>
  
  <hr>
  
  <p>I solved my problem. 
  firstly, you can add this code</p>
  
  <pre><code>VideoCapture cap;
  cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
  cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480); 
  </code></pre>
  
  <p>then add this code in while loop:</p>
  
  <pre><code>cap.read(image);
  </code></pre>