The color to grayscale algorithm is stated in the cvtColor() documentation. (search for RGB2GRAY). The formula used is the same as for CCIR 601:
Y = 0.299 R + 0.587 G + 0.114 B
The luminosity formula you gave is for ITU-R Recommendation BT. 709. If you want that you can specify CV_RGB2XYZ
(e.g.) in the third parameter to cvtColor()
then extract the Y channel.
You can get OpenCV to to do the "lightness" method you described by doing a CV_RGB2HLS
conversion then extract the L channel. I don't think that OpenCV has a conversion for the "average" method,
but if you explore the documentation you will see that there are a few other possibilities.