ofxCvImage Region of Intereset - ROI

Hey there,

I’ve never worked with ROIs but it seems to be the easiest way to mask a region in an ofxCvGrayscaleImage.

My question would be is it possible to run in to a runtime error because of bad access when setting ROIs ?

For example:

roiWidth = grayscaleImg.getWidth() / 3.0;
roiHeight = grayscaleImg.getHeight() / 3.0;

for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					grayscaleImg.setROI((roiWidth * i + roiWidth) > grayscaleImg.getWidth() ? grayscaleImg.getWidth() - roiWidth : roiWidth * i,
						(roiHeight * j + roiHeight) > grayscaleImg.getHeight() ? grayscaleImg.getHeight() - roiHeight : roiHeight * j, roiWidth, roiHeight);
                                }
                      } 

Here I’m trying seperating my image into 9 areas an i would like to know if there is a code that would know if my roiHeight * 3 would be bigger then grayscaleImg.getHeight() like I do it myself in my code.

I wanted to get rid of a conditioning in my function but that seems the safest way for me right now.

Hey @Phoenix03 , I looked in ofxCvImage.cpp, and the .setROI() function does clamp values to the dimension of the image. If you haven’t already, you can always do some stuff to test it too, like call .setROI() with something you know should fail and then output the results of .getROI() just to check them and see what they are (provided it doesn’t crash).