#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
bool main()
{
Mat src = imread("1.jpg");
Mat dst;
cvtColor(src,dst,CV_RGB2GRAY);
int dstLength = dst.cols;
int dstHeight = dst.rows;
for (int i = 0; i < dstHeight; ++i)
{
uchar* data = dst.ptr<uchar>(i);
for (int j = 0; j < dstLength; ++j)
{
int T = 125;
data[j] = data[j] >= T ? 255 : 0;
}
}
imshow("【原始图片】",src);
imshow("【灰度图片】",dst);
waitKey(0);
}
图像基本二值化实现
