#include <iostream>
#include"opencv.hpp"
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
int row, col;
float red = 0.299;
float blue = 0.587;
float green = 0.114;
int i, j;
VideoCapture capture(0);
while (1)
{
Mat image;
int row, col;
capture >> image;
row = image.rows;
col = image.cols;
Mat gray(row, col, CV_8UC1);
uchar* data;
for (i = 0; i < row; i++)
{
data = gray.ptr<uchar>(i);
for (j = 0; j < col; ++j)
{
data[j] = (int)(image.at<Vec3b>(i,j)[0]*blue + image.at<Vec3b>(i, j)[1] * green + image.at<Vec3b>(i, j)[2] * red);
}
}
imshow("", gray);
if (waitKey(30) == 27)
{
cout << "按下ESC键" << endl;
break;
}
}
return 0;
}