Ok, there’s a couple ways you can handle this problem.
Inside the ofxContourFinder.cpp class, there’s a inputCopy ofxGrayscaleImage. It is allocated based on the height/width of the image. In the case below, the height width of grayDiff is passed in.
cvSetImageROI(grayDiff.getCvImage(), cvRect(0,0,200,200));
contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true); // find holes
cvResetImageROI(grayDiff.getCvImage());
The problem is, the image is using ROI and height width of the grayDiff image doesn’t report the ROI height/width (it reports the full image height/width) which is needed for allocation of the inputCopy image. Therefore, when the following code occurs:
inputCopy = input;
You are setting the inputCopy (which is full height/width of the image) = to input (which is only ROI height/width). This will crash since the sizes aren’t the same.
Method 1) In ofxContourFinder you can add the code:
CvRect rect = cvGetImageROI(input.getCvImage()); //thiss will get the input (graydiff) ROI box
cvSetImageROI(inputCopy.getCvImage(), rect )//this sets the copy of the input to ROI
That will make them both have the same ROI and therefore the same size. You would need to place that code everywhere before you see
inputCopy = input;
in the ofxContourFinder class.
Method 2) You can copy the ROI image into a separate image before you pass it to contourFinder.
For example:
cvSetImageROI(grayDiff.getCvImage(), cvRect(0,0,200,200)); //set the ROI
grayDiffROI.allocate(grayDiff.getCvImage()->roi->width, grayDiff.getCvImage()->roi->height); //set the grayDiffROI to the size of only the ROI
grayDiffROI = grayDiff; //copy the ROI image to the grayDiffROI image
contourFinder.findContours(grayDiffROI, 20, (340*240)/3, 10, true); // find holes
cvResetImageROI(grayDiff.getCvImage());
You’d also have to have some if statement where the grayDiffROI.allocate would go so that you only allocate when the ROI size changes. This method makes it so you don’t have to edit any core classes. I haven’t tested this one, but it should work and will probably be what I switch to.
I’m sure others might have other/better ways too.