I have gotten good results using OpenMP. Something like the following should work. In my example, I am only interested in the best/biggest face in each image. Change that part, obviously, if you want more than one.
#include <omp.h>
cv::CascadeClassifier faceFinder_[4];
cv::Rect faceBounds[4];
#pragma omp parallel for // num_threads( 4 )
for( int tt=0; tt < 4; ++tt )
{
FindBestFace( faceFinder_[tt], rectifiedGray[tt], faceBounds[tt] );
}
static void FindBestFace( cv::CascadeClassifier & finder, const cv::Mat & srcImg, cv::Rect & faceBounds )
{
vector< cv::Rect> faces;
int minFaceDiameter = srcImg.cols / 6;
finder.detectMultiScale( srcImg, faces,
1.1, 2, 0
//|CV_HAAR_FIND_BIGGEST_OBJECT
//|CV_HAAR_DO_ROUGH_SEARCH
|CV_HAAR_SCALE_IMAGE
,
cv::Size(minFaceDiameter, minFaceDiameter) );
if( faces.empty() )
{
faceBounds = cv::Rect( 0, 0, 0, 0 );
}
else
{
faceBounds = faces[0];
}
}