指针读取像素:
#include"opencv2/opencv.hpp"
using namespace cv;
void main()
{
Mat img = imread("E:\\1.jpg");
Mat dst = img.clone();
int row = img.rows;
int colNumber = img.cols*img.channels();//列乘以3,获得每一行的通道数
for (int i = 0; i < row; i++)
{
uchar*data = dst.ptr<uchar>(i);//定义一个uchar类型的指针
for (int j = 0; j < colNumber; j++)
{
switch (j%3)//对3取余,然后对每一个通道赋值
{
case 0:
data[j] = 255;
break;
case 1:
data[j] = 255;
break;
case 2:
data[j] = 0;
break;
default:
break;
}
}
}
imshow("原图",img);
imshow("处理后的图片",dst);
waitKey(0);
destroyAllWindows();
}
结果: