title: OpenCV Slow camera framerate
body: <p>I just copied an program to detect faces through webcam but the video capture is really slow, and i dont know how to fix it!</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  #include&lt;opencv\cv.h&gt;
  #include&lt;opencv\highgui.h&gt;
  #include&lt;opencv2\objdetect\objdetect.hpp&gt;
  #include&lt;opencv2\highgui\highgui.hpp&gt;
  #include&lt;opencv2\imgproc\imgproc.hpp&gt;
  #include&lt;vector&gt;
  
  using namespace cv;
  using namespace std;
  
  int main()
  {
  CascadeClassifier face_cascade;
  if(!face_cascade.load("c:\\haar\\haarcascade_frontalface_alt2.xml")) {
      printf("Error loading cascade file for the face");
      return 1;
  }
  VideoCapture capture(0);
  if(!capture.isOpened())
  {
      printf("Error trying to start the Camera");
      return 1;
  }
  Mat cap_img,gray_img;
  vector&lt;Rect&gt; faces;
  while(1)
  {
      capture &gt;&gt; cap_img;
      waitKey(10);
      cvtColor(cap_img, gray_img, CV_BGR2GRAY);
      cv::equalizeHist(gray_img,gray_img);
      face_cascade.detectMultiScale(gray_img, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));
      for(int i=0; i &lt; faces.size();i++)
      {
          Point pt1(faces[i].x+faces[i].width, faces[i].y+faces[i].height);
          Point pt2(faces[i].x,faces[i].y);
          rectangle(cap_img, pt1, pt2, cvScalar(191,191,191), 2, 8, 0);
      }
      imshow("Result", cap_img);
      waitKey(3);
      char c = waitKey(3);
      if(c == 27)
          break;
  }
  return 0;
  }
  </code></pre>
  
  <p>I am using Visual studio 2012 and this is the main.cpp file. Im using OpenCV 2.4.9!</p>