The formula says:
Y = 0.299 * R + 0.587 * G + 0.114 * B; U = -0.14713 * R - 0.28886 * G + 0.436 * B; V = 0.615 * R - 0.51499 * G - 0.10001 * B;
You can convert RGB<->YUV in OpenCV with cvtColor using the code CV_YCrCb2RGB for YUV->RGB and CV_RGBYCrCb for RGB->YUV.
code
CV_YCrCb2RGB
CV_RGBYCrCb
void cvCvtColor(const CvArr* src, CvArr* dst, int code)
Converts an image from one color space to another.