ofxCv: set and ROI

Hi !
I am having some strange behavior and I would like to have some lighting on how the function set behave towards roi…

Here is a part of my code

for (int i = 0; i < mesure; i++){  
	for (int j = 0; j < octave; j++){  
		nonZeroMatrixBlock = matrixImg.countNonZeroInRegion(i*sizeMesure, j*sizeOctave, (i+1)*sizeMesure, (j+1)*sizeOctave);  
			matrixImg.setROI(i*sizeMesure, j*sizeOctave, (i+1)*sizeMesure, (j+1)*sizeOctave);  
			sampleMatrix[i+j*mesure] = 1;  
			matrixImg.setROI(i*sizeMesure, j*sizeOctave, (i+1)*sizeMesure, (j+1)*sizeOctave);  
			sampleMatrix[i+j*mesure] = 0;  

I just go through an image and check for non-zero values.
If the value is higher than the threshold then I would like to set this ROI to 255.0 else to 0.
But does the function set take into account the ROI ?..

thanks in advance :slight_smile:

yes set() operates only on the ROI.

also, unless you are doing this for kicks … you can use the threshold() function instead :wink:

Thank you for your answer !

It seems my main problem was on the threshold ->“nonZeroThreshold” >.<
During the development I changed the sizeMesure/sizeOctave -> changing the number of pixels inside ROI -> changing the “nonZeroThreshold” value dramastically lol

After founding this I haven’t try the set() function again… I was testing by doing a setRoiFromPixels() lol

So, I’ll have to try the 3 methods:

  • copying a matrix of zero or 255 with the setRoiFromPixels()
  • set()
  • threshold()

I hope to get the same results :stuck_out_tongue:

Thank you very much for the threshold() trick!! :slight_smile:
I’ll try it tonight
By the way, wouldn’t set() be faster than threshold()… (mustn’t change a lot still lol)

Indeed I use the sampleMatrix… the matrixImg is just to visualize it somehow…