title: Can't capture Video from Cam in OpenCV 2.4.7
body: <p>This is my code which I copy/paste from <a href="http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture" rel="nofollow">here</a>:</p>
  
  <pre><code>#include "opencv2/opencv.hpp"
  
  using namespace cv;
  
  int main(int, char**)
  {
      VideoCapture cap(0); // open the default camera
      if(!cap.isOpened())  // check if we succeeded
          return -1;
  
      Mat edges;
      namedWindow("edges",1);
      for(;;)
      {
          Mat frame;
          cap &gt;&gt; frame; // get a new frame from camera
          cvtColor(frame, edges, CV_BGR2GRAY);
          GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
          Canny(edges, edges, 0, 30, 3);
          imshow("edges", edges);
          if(waitKey(30) &gt;= 0) break;
      }
      // the camera will be deinitialized automatically in VideoCapture destructor
      return 0;
  }
  </code></pre>
  
  <p>But I get this error:</p>
  
  <hr>
  
  <pre><code>OpenCV error: Assertion failed (scn==3 || scn==4) 
  in unknown function, file ..\..\..\..\opencv\modules\imgproc\src\color.cpp, line 3737
  </code></pre>
  
  <hr>
  
  <p>I am using Windows 7 x64, Visual Studio 2008, OpenCV 2.4.7</p>
  
  <p>What can be the problem?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It is sometimes it works, sometimes it does not.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I edited <strong>VideoCapture cap(0);</strong> to <strong>cv::VideoCapture cap(0);</strong> then, I rebuild my solution and run it. It worked for the first time, I tried to run for the second time, it gave me the same error.</p>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>I have even edited <strong>for(;;)</strong>:</p>
  
  <pre><code>for(;;)
      {
          Mat frame;
          cap &gt;&gt; frame; // get a new frame from camera
          imshow("edges", frame);
          if(waitKey(30) &gt;= 0) break;
      }
  </code></pre>
  
  <p>This time I receive another error:</p>
  
  <hr>
  
  <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>
  
  <hr>
  
  <p>I guess the problem is with <strong>imshow</strong>.</p>