title: OpenCv error when initializing camera with VisualStudio C++ 2010
body: <p>I'm new to opencv programming, so maybe my question will be very stupid. But i have such problem, i took one sample code, which should enable laptop webcamera to show image in desktop.</p>
  
  <pre><code>#include &lt;opencv\cv.h&gt; 
  #include &lt;opencv\highgui.h&gt; 
  
  using namespace cv;
  
  int main()
  {
  Mat image;   //create Matrix to store image
  VideoCapture cap;
  cap.open(0);     // initialize capture
  namedWindow("window", CV_WINDOW_AUTOSIZE);  // create window to show image
  
  while(1)
  {
  cap&gt;&gt;image;  // copy webcam stream to image
  imshow("window", image);   // print image to screen
  waitKey(33);      // delay 33ms
  }
  return 0;
  }
  </code></pre>
  
  <p>But when i'm trying to debug it  i get an error message.</p>
  
  <blockquote>
    <p>Unhandled exception at 0x5a16ebe6 in myNewOpenCV.exe: 0xC0000005: Access violation reading location 0x00000018.</p>
  </blockquote>
  
  <p>But if i put breakpints on </p>
  
  <pre><code>cap&gt;&gt;image;
   imshow("window", image);   // print image to screen`
  </code></pre>
  
  <p>and after debuging im taking it off everything work correctly. Maybe someone can help to find a problem. Thanks.</p>