#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
using namespace cv;
using namespace std;
void RemoveSmallRegion(Mat& Src, Mat& Dst, int AreaLimit = 50, int CheckMode = 1, int NeihborMode = 0);
int main()
{
Mat SrcImage = imread("11.png");
namedWindow("原图", 2);
imshow("原图", SrcImage);
int height = SrcImage.rows;
int width = SrcImage.cols;
//cout << height << " " << width <<endl;
//指针访问数组
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
//取出图片第i行第j列的像素
uchar *p = SrcImage.ptr<uchar>(i,j);
//当为单通道图片时,直接用p[0]访问
if (i == j) //当i=j时 将像素赋值为红色
{
p[0] = 0;
p[1] = 0;
p[2] = 255;
}
}
}
namedWindow("处理图", 1);
imshow("处理图", SrcImage);
waitKey(0);
return 0;
}
结果显示: