The cv::cvtColor function call can be used to convert between different image formats in OpenCV.
The header file to include is
opencv2/opencv.hpp.
The library file to link with on Windows is
opencv_imgproc249.lib for Release mode and
opencv_imgproc249d.lib for Debug mode. This assumes that I
am using OpenCV 2.4.9.
As an example of usage, to convert from RGB to
BGR format:
cv::Mat in_mat; // Holds RGB image
cv::Mat out_mat; // Output in BGR format
cv::cvtColor(in_mat, out_mat, CV_RGB2BGR);
CV_RGB2GRAY convert 3-channel RGB image to 1-channel
grayscale image.Tried with: OpenCV 2.4.9 and Windows 7 Professional 64-bit