title: Assertion failed (size.width>0 && size.height>0)
body: <p>I'm using Visual Studio Express 2013 with OpenCV <code>2.4.7</code>, following this <a href="http://www.youtube.com/watch?v=cgo0UitHfp8" rel="noreferrer">tutorial</a>.</p>
  
  <p>I have spent hours searching the web for solutions, including all of the relevant SO questions.  I have tried:</p>
  
  <ul>
  <li><p>the return value of <code>VideoCapture::open</code>   is 1</p></li>
  <li><p>extending the waitKey() delay to 50ms and later 500ms</p></li>
  <li><p>setting the dimensions of the window</p></li>
  <li><p>creating another project on Visual C++</p></li>
  <li><p>opening an existing image instead of reading from camera (same error)</p></li>
  </ul>
  
  <p>but no luck, please help!</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;opencv/cv.h&gt;
  #include &lt;opencv/highgui.h&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  using namespace cv;
  
  int main() {
      Mat image;
  
      VideoCapture cap;
      int camOpen = cap.open(CV_CAP_ANY);
  
      namedWindow("window", CV_WINDOW_AUTOSIZE);
  
      while (true) {
          cap &gt;&gt; image;
  
          imshow("window", image);
  
      // delay 33ms
      waitKey(33);        
      }
  
  }
  </code></pre>
  
  <p>As I compiled and ran it, I got the following error:</p>
  
  <blockquote>
    <p>OpenCV Error: Assertion failed (size.width>0 &amp;&amp; size.height>0) in cv::imshow, file ........\opencv\modules\highgui\src\window.cpp, line 261</p>
  </blockquote>
  
  <p>Error occurs at the line     <code>imshow("window", image);</code>.  When I commented it out, there are no complaints.</p>
  
  <hr>
  
  <p>UPDATES:</p>
  
  <p>A plausible explanation of why this error occured was that my webcam takes time to start, which is why image.empty()  is true initially, hence the abort() function was called to exit the program.</p>
  
  <p>With the code</p>
  
  <pre><code>if (!image.empty()) {
      imshow("window", image);
  }
  </code></pre>
  
  <p>we can wait for the camera to start</p>