title: Unhandled exception , access violation in opencv cvCaptureFromCAM using Visual c++
body: <p>I am trying to build a program in Opencv that captures a video and saves it to a file. However, after repeated efforts I continue to get this error : Unhandled exception at 0x201e8efb in basic.exe: 0xC0000005 Access violation, where basic.cpp is my file name.
  The same occurs when trying to capture an image.
  I have already tried changing cvCaptureFromCAM parameters to CV_CAP_ANY/0/-1/-2/1/2..but none of these worked out.My webcam, works perfectly well for others applications and i have tested it online.
  Any help would be greatly appreciated .Thanks in advance.</p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include "C:\opencv\build\include\opencv2\core\core.hpp"
  #include "C:\opencv\build\include\opencv2\highgui\highgui.hpp"
  #include &lt;iostream&gt;
   using namespace cv;
  
   using namespace std;
  
  void main( ){
  
      CvCapture *capture = cvCaptureFromCAM( 0 );
      int width = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH );
      int height = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT );
      CvVideoWriter *writer = cvCreateVideoWriter( "myCamCapture.avi", -1, 30, cvSize( width, height ) );
      cvNamedWindow("camopen", CV_WINDOW_AUTOSIZE);
      IplImage *frame = 0;
  
      while( 1 )
      {
          frame = cvQueryFrame( capture );
          cvShowImage("d",frame);
          cvWriteFrame( writer, frame );
          char c = cvWaitKey( 30 );
          if( c == 27 ) break;
      }
  }
  </code></pre>