// Test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
#include
using namespace cv;
using namespace std;
int main()
{
string path = "D:\\temp\\label\\image3.png";
Mat src = imread(path);
Mat src8bit = Mat::zeros(Size(src.cols, src.rows), CV_8UC1);
float R, G, B;
R = 0.299;
G = 0.387;
B = 0.114;
//R = 0.109;
//G = 0.387;
//B = 0.340;
for (int i = 0; i < src.rows; i++)
{
uchar* data = src.ptr(i);
for (int j = 0; j < src.cols * 3; j = j + 3)
{
int r, g, b, val;
r = R * data[j];
g = G * data[j + 1];
b = B * data[j + 2];
val = r + g + b;
src8bit.at(i, j / 3) = val;
}
}
return 0;
}