opencv中应用step访问图像像素

#include "stdafx.h"
#include "opencv.hpp"

using namespace std;
using namespace cv;
int main()
{
	Mat grayImage, dstImage;
	Mat Image = imread("1.png");
	imshow("原图", Image);
	cvtColor(Image, grayImage, COLOR_RGB2GRAY);

	imshow("灰度图", grayImage);
	/*threshold(grayImage, dstImage, 100, 255, THRESH_BINARY);
	imshow("二值化图", dstImage);*/
	int height = grayImage.rows;
	int width = grayImage.cols;
	uchar *data = grayImage.data;
	uchar *data1 = Image.data;

	for (int i = 0; i < height; i++)
	{
		for (int j = 0; j < width; j++)
		{
			if (i == j)
			{
				data[i*grayImage.step + j] = 150;
				data1[i*grayImage.step*3 + j*3] = 5;
			}
		}
	}
	imshow("原图1", Image);
	imshow("灰度图1", grayImage);
	waitKey(0);
    return 0;
}

显示结果:

opencv中应用step访问图像像素_第1张图片

opencv中应用step访问图像像素_第2张图片

opencv中应用step访问图像像素_第3张图片

你可能感兴趣的:(opencv,c++,图像处理,opencv基础,图像处理)