LED webcam effect running very slowly

Hi there

I’m new to openFrameworks (have some experience of processing) and have been trying to create a stylised version of my webcam’s input. It works but is running very slowly - I have no idea why it is so slow - I have this code in the draw loop. Could anyone point me in the right direction or give me some tips as to why it is so slow? Here is the code (I have tweaked what I could find in the documentation):

  
for (int i = 4; i < 320; i+=8){  
  
			for (int j = 4; j < 240; j+=8){  
				  
				unsigned char * pixels = colorImg.getPixels();  
				  
				int red 	= pixels[(j * 320 + i) * 3     ];  
				int green 	= pixels[(j * 320 + i) * 3 + 1];  
				int blue 	= pixels[(j * 320 + i) * 3 + 2];  
				  
				ofSetColor(red, green, blue, 75);  
				ofRect(10 + i * 2, 10 + j * 2, 15, 15);  
				  
			}   
		}   
  

Any help or tips would be greatly appreciated.

Thanks!

generally try to move things out of loops especially nested loops. In your case

unsigned char * pixels = colorImg.getPixels();

should be done before you enter the loops.

hope this helps,

That works a treat! Thanks very much Stefan!