void ofxGreenscreen::learnBgColor(ofPixelsRef pixelSource, int x, int y, int w, int h) { int wh = w * h; int r,g,b; r=g=b=0; for(int iy=0; iy<h; iy++) { for(int ix=0; ix<w; ix++) { int i = pixelSource.getPixelIndex(ix+x, iy+y); r+=pixelSource[i]; g+=pixelSource[i+1]; b+=pixelSource[i+2]; } } r/=wh; g/=wh; b/=wh; bgColor.set(r, g, b); update(); }