#include "stdafx.h"
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<vector>
using namespace std;
using namespace cv;
int main()
{
Mat src;
//读取源彩色图片
src = imread("E:\test2.jpg");
Mat src_t(src.rows, src.cols, CV_8UC1);
if (!src.data) { printf("Error loading src
"); return -1; }
double r = 0, b = 0, g = 0, grayLevel = 0;
for (int i = 0; i < src.rows; i++)
for (int j = 0; j < src.cols; j++)
{
b = src.at<Vec3b>(i, j)[0];
g = src.at<Vec3b>(i, j)[1];
r = src.at<Vec3b>(i, j)[2];
grayLevel = r*0.299 + g*0.587 + b*0.114;
if (grayLevel>192)
src_t.at<uchar>(i, j) = 0;
else
src_t.at<uchar>(i, j) = 255;
}
imshow("1", src_t);
waitKey(0);
return 0;
}