#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main (int argc, char **argv) {
Mat image = imread("../ubuntu.png");
imshow("ee", image);
for (size_t y =0; y<image.rows;y++)
for(size_t x = 0;x<image.cols; x++)
{
//方式一:
unsigned char * row_ptr = image.ptr<unsigned char>(y);
unsigned char * data_ptr = &row_ptr[x*image.channels()];
for (int c = 0; c!=image.channels(); c++){
unsigned char data = data_ptr[c];
//cout<<data<<endl;
printf("%u \n", data);
}
//方式二:
/×
MAT类部分成员的意思
image.channels():图像的通道数,RGB图像为三通道。
image.total():图像总的像素个数。
img.step:表示图像矩阵中每行所包含的字节数。
img.elemSize():图像中每个像素点所包含的字节数。
×/
//unsigned char *data = image.ptr<unsigned char>(y)[x];
//cout<<image.data[y*image.step+x*image.channels()]<<endl;
printf("%u-%u-%u \n", image.data[y*image.step+x*image.channels()],
image.data[y*image.step+x*image.channels()+1],
image.data[y*image.step+x*image.channels()+2]);
}
waitKey(0);
return 0;
}
访问每个像素点的像素值
最新推荐文章于 2023-12-04 18:54:43 发布