ROI in ofxCvHaarFinder

Hi. I’m using ofxCvHaarFinder (fresh clone from github) to detect faces, mouths and eyes.
I’m using a different instance to detect each feature. Given that the eyes and mouth are inside the face, I’m settiing the ROI of those to be the bounding rect of the detected face.

if(faceFinder.blobs.size() > 0) {  
        ofRectangle faceRect = faceFinder.blobs[0].boundingRect;  
        eyeROI.set(faceRect.x, faceRect.y, faceRect.width, faceRect.height/2); // only top half  
        eyeFinder.findHaarObjects(vidGrayImg,  eyeROI);  
        mouthROI.set(faceRect.x , faceRect.y+ faceRect.height/2, faceRect.width, faceRect.height/2); // only bottom half  
        mouthFinder.findHaarObjects(vidGrayImg, mouthROI);  

I’m doing this on a keypress, and I was getting the error

OF_ERROR: in =, ROI mismatch   

In findHaarObjects, we have the setROI after making the copy of the input image, so if the internal img of the haarfinder has a previous ROI, this fails.

I’ve solved it for the moment by resetting the ROI before making the copy,

int ofxCvHaarFinder::findHaarObjects(const ofxCvGrayscaleImage& input,  
	int x, int y, int w, int h,  
	int minWidth, int minHeight) {  
		if (img.width == input.width && img.height == input.height) {  
                     img = input;  
		} else {  
		     img.allocate(input.width, input.height);  
		     img = input;  
		img.setROI(x, y, w, h);  

but am not 100% sure if this is a good thing to do. another option would be to provide a public resetROI function to the ofxCvHaarFinder.

Is this an issue or am I misunderstanding ROI. If it is I’ll raise it on github.


post an issue just in case :slight_smile: