1 void RgbConvToGray(const Mat& inputImage, Mat & outpuImage)
2 {
3 outpuImage = Mat(inputImage.rows, inputImage.cols, CV_8UC1);
4
5 for (int i = 0; i < inputImage.rows; ++i)
6 {
7 uchar* ptr = outpuImage.ptr<uchar>(i);
8 Vec3b* rgb = outpuImage.ptr<Vec3b>(i);
9 for (int j = 0; j < inputImage.cols; ++j)
10 {
11 ptr[j] = 0.3*rgb[j][2] + 0.59*rgb[j][1] + 0.11*rgb[j][0];
12 }
13 }