title: Accessing Webcam using OpenCV - C++
body: <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include&lt;opencv2/objdetect/objdetect.hpp&gt;
  #include&lt;opencv2/imgproc/imgproc.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include&lt;iostream&gt;
  
  using namespace cv;
  
  void load(CascadeClassifier &amp;a)
  {
      try{
          a.load("F:/Projects/workspace/dispimage/src/lbpcascade_frontalface.xml");
      }
      catch(cv::Exception &amp;e) {
          std::cout&lt;&lt;"Cannot load the qwespecified file";
      }
      if ( a.empty() ){
          std::cout &lt;&lt; "ERROR: Couldn't load Face Detector (";
          std::cout&lt;&lt;")!";
          exit(1);
      }
  }
  
  void open(VideoCapture &amp;camera)
  {
      camera.open(0);
          if(!camera.isOpened())
          {
              std::cout&lt;&lt;"Camera did not open";
              exit(1);
          }
  
          camera.set(CV_CAP_PROP_FRAME_WIDTH, 640);
          camera.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
  }
  
  int main() {
  
      CascadeClassifier a;
      VideoCapture camera;
      namedWindow("CamerOP",CV_WINDOW_AUTOSIZE);
      bool b =0;
  
      load(a);
      open(camera);
  
      while (true)
      {
        // Grab the next camera frame.
          Mat cframe;
           b=camera.read(cframe);
            if (!b)
            {
              std::cerr &lt;&lt; "ERROR: Couldn't grab a camera frame." &lt;&lt;std::endl;
              exit(1);
            }
  
            imshow("CamerOP",cframe);
      }
  
  
      std::cout&lt;&lt;"Haillo";
  
      return 1;
  }
  </code></pre>
  
  <p>I am trying to access my webcam using opencv. The imagewindow i created opens up and resizes itself to 640*480, then it just goes not responding with the content area being all gray. I am not able to figure it out as i have seen several howtos on this and more or less every place has done the same thing.</p>
  
  <p>Heres a Screenshot - <img src="https://i.stack.imgur.com/daVJt.png" alt="Screen"></p>