Courtesy of the OpenCV 2.3 GPU code comes a neat snippet of code for using a template parameter for reading RGB or BGR ordered components when dealing with RGB triplets.
The Code ∞ 1 2 3 4 5 template <int blueIndex> float rgb2grey(const float *src) { return 0.114f*src[blueIndex^2] + 0.587f*src[1] + 0.299f*src[blueIndex]; }
Then [...]
