How to find the average colour from a video feed

Hello,

I have been playing around with the openCV example and I have created a grid of squares which react in a very basic sense to movement. I would like each of the squares to take on a set of colours which are most prominent in the video feed.

Please could someone provide me with help to find the average colour within my video feed, so I can change the squares to always update to the average colour. The project can be downloaded at the url below. It is currently setup with xcode.

http://www.wearetheparklane.co.uk/storage/average-colour-help.zip

How about cvAvgSdv()?

  
IplImage* iplImg = colorImg.getCvImage();  
CvScalar mean; CvScalar stdv;		  
cvAvgSdv(iplImg, &mean, &stdv);  
cout << "mean r = "+ofToString(mean.val[0])+" mean g = "+ofToString(mean.val[1])+" mean b = "+ofToString(mean.val[2]) << endl;  
cout << "stdv r = "+ofToString(stdv.val[0])+" stdv g = "+ofToString(stdv.val[1])+" stdv b = "+ofToString(stdv.val[2]) << endl;  

colorImg is ofxCvColorImage(inheritance of ofxCvImage).
You can get mean(average) and standard deviation value from image colors.

hope this help…