Multithreading (ofxRuiThread) and openCV

Okay so a little background as to whats happening and what i’m doing. I’m trying to do parallel processing of ofxCvHaarFinder. To do this i preprocess my image to determine possible regions of interest where a face may exist, then i intend to parallize the the haar detection process over multiple threads. Now i implemented this using ofxRuiThread ofx addon. Now the problem that i’m having say i have 5 threads allocated for the haar finder i.e. 5 possible face detection ROIs can be processed simultaneously, and i detect one face roi so i do the detection of the face in the first worker thread and all is good i get a processing time of 30ms for one face.

Now however if there are >1, say 2 face ROIs both of the same size the frame processing time jumps to 100ms now what i don’t understand is why it does this i would assume up till 5 faces ROIs of the same size the time should remain more or less 30ms and not increase as it does. Because at 3 ROIs it jumps to 150ms so on and so forth.

  
  
if(ROIs.size() > 0){  
	int nROI = 0;  
	bool breakROIs = false;  
	bool threadsBusy = false;  
	  
	int totalROIs = ROIs.size();  
	int itterations = totalROIs %  5;  
  
	while(nROI < ROIs.size()){  
		int nNThread = 0;  
		while(nNThread < cvHaarThreads.size()){  
			cvHaarThreads[nNThread]->grayImage = grayImage;  
			cvHaarThreads[nNThread]->ROI = ROIs[nROI];  
			cvHaarThreads[nNThread]->updateOnce();  
			nROI++;  
			if(nROI< ROIs.size()){  
				nNThread++;  
				if(nNThread < cvHaarThreads.size()){  
					//  
				}  
				else{  
					threadsBusy = true;  
					break;  
				}  
			}  
			else{  
				breakROIs = true;  
				break;  
			}  
					  
		}  
		if(threadsBusy){  
			for(int i = 0; i < cvHaarThreads.size(); i++){  
				cvHaarThreads[i]->waitToFinish();  
			}  
		}  
		if(breakROIs){  
			if(itterations > 0){  
				for(int i = 0; i < cvHaarThreads.size(); i++){  
					cvHaarThreads[i]->waitToFinish();  
				}  
			}  
			break;  
		}  
	}  
}  
int nThread = 0;  
while(nThread < cvHaarThreads.size()){  
	// retrieve blobs;  
	if(cvHaarThreads[nThread]->facesDetected){  
		for(int i = 0; i < cvHaarThreads[nThread]->faceBlobs.size(); i++){  
			int numBlobsInThread = cvHaarThreads[nThread]->faceBlobs.size();  
			ofxCvBlob faceBlob = cvHaarThreads[nThread]->faceBlobs[i];  
			faceBlobs.push_back(faceBlob);  
		}  
		// clear blobs  
		cvHaarThreads[nThread]->faceBlobs.clear();  
		cvHaarThreads[nThread]->facesDetected = false;  
	}  
	if(!cvHaarThreads[nThread]->faceBlobs.empty()){  
		// clear blobs  
		cvHaarThreads[nThread]->faceBlobs.clear();  
	}  
	nThread++;  
}