title: Using opencv + viola jones running slow
body: <p>I am trying to implement Face detection viola jones classifier using opencv cascade. This is the code i am using:</p>
  
  <pre><code>int main( ){
  SYSTEMTIME tm;
  
  GetLocalTime(&amp;tm);
  printf("Date: %02d.%02d.%d, %02d:%02d:%02d:%02d\n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
  //CString t = CTime::GetCurrentTime().Format("%H:%M:%S:%MS");
  Mat image;
  Mat frame_gray;
  
  image = imread("test.jpg", CV_LOAD_IMAGE_COLOR); 
  namedWindow( "window1", 1 );   imshow( "window1", image );
  
  
  // Load Face cascade (.xml file)
  CascadeClassifier face_cascade;
  face_cascade.load( "cascades.xml" );
  
  
  
  cvtColor( image, frame_gray, CV_BGR2GRAY );
  equalizeHist( frame_gray, frame_gray );
  
  
  GetLocalTime(&amp;tm);
  printf("Date: %02d.%02d.%d, %02d:%02d:%02d:%02d\n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
  float pyramidScale = 1.5f;
  // Detect faces
  std::vector&lt;Rect&gt; faces;
  face_cascade.detectMultiScale( frame_gray, faces, pyramidScale, 3, 0, Size(20, 20), Size(50, 50));
  
  GetLocalTime(&amp;tm);
  printf("Date: %02d.%02d.%d, %02d:%02d:%02d:%02d\n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
  
  // Draw circles on the detected faces
  for( int i = 0; i &lt; faces.size(); i++ )
  {
      Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
      ellipse( image, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 255, 255 ), 4, 8, 0 );
  }
  
  imshow( "Detected Face", image );
  
  
  SYSTEMTIME tm1;
  GetLocalTime(&amp;tm);
  printf("Date: %02d.%02d.%d, %02d:%02d:%02d:%02d\n", tm.wDay, tm.wMonth, tm.wYear, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);
  //cout&lt;&lt; "Time : "&lt;&lt;tm.wHour&lt;&lt;":"&lt;&lt;tm.wMinute &lt;&lt; ":"&lt;&lt; tm.wSecond &lt;&lt; ":" &lt;&lt; tm.wMilliseconds &lt;&lt; "\n";
  waitKey(0);                  
  return 0;
  }
  </code></pre>
  
  <p>The problem is it says this is viola jones implementation in opencv and usually takes 30fps to run (from the author side) but its taking 6 seconds to run a normal HD image for face detection of around 1920x1080. I wanted to ask is the implementation right or is there any problem with the way i am implementing the method and is there any way i can make it faster ? The cascade.xml is a file i trained using sample images. Thank you.</p>