title: Opencv - Haar cascade - Face tracking is very slow
body: <p>I have developed a project to tracking face through camera using OpenCV library.
  I used haar cascade with <code>haarcascade_frontalface_alt.xml</code> to detect face. </p>
  
  <p>My problem is if image capture from webcame doesn't contain any faces, process to detect faces is very slow so images from camera, which are showed continuosly to user, are delayed. </p>
  
  <p>My source code: </p>
  
  <pre><code>void camera() 
  {
      String face_cascade_name = "haarcascade_frontalface_alt.xml";
      String eye_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
      CascadeClassifier face_cascade;
      CascadeClassifier eyes_cascade;
      String window_name = "Capture - Face detection";
      VideoCapture cap(0);
  
      if (!face_cascade.load(face_cascade_name))
          printf("--(!)Error loading\n");
  
      if (!eyes_cascade.load(eye_cascade_name))
          printf("--(!)Error loading\n");
  
      if (!cap.isOpened()) 
      {
          cerr &lt;&lt; "Capture Device ID " &lt;&lt; 0 &lt;&lt; "cannot be opened." &lt;&lt; endl;
      } 
      else 
      {
          Mat frame;
          vector&lt;Rect&gt; faces;
          vector&lt;Rect&gt; eyes;
          Mat original;
          Mat frame_gray;
          Mat face;
          Mat processedFace;
  
          for (;;) 
          {
              cap.read(frame);
              original = frame.clone();    
              cvtColor(original, frame_gray, CV_BGR2GRAY);
              equalizeHist(frame_gray, frame_gray);
              face_cascade.detectMultiScale(frame_gray, faces, 2, 0,
                      0 | CASCADE_SCALE_IMAGE, Size(200, 200));
  
              if (faces.size() &gt; 0)
                  rectangle(original, faces[0], Scalar(0, 0, 255), 2, 8, 0);
  
              namedWindow(window_name, CV_WINDOW_AUTOSIZE);
              imshow(window_name, original);
          }
  
          if (waitKey(30) == 27)
              break;
      }
  }
  </code></pre>