#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
//【1】创建原始图并显示
Mat srcImage = imread("D:\\pictures\\lena.jpg",0);
int width = srcImage.rows;
int height = srcImage.cols;
cout << "width=" << width<< endl << "hight=" << height << endl;
uchar* ptr = srcImage.data;
for (int row = 0; row<height; row++)
{
uchar* data = srcImage.ptr<uchar>(row);//获得灰度值数据指针
for (int cols = 0; cols<width; cols++)
{
int intensity = ptr[cols];
cout <<(int) intensity << " ";
}
}
system("pause");
return 0;
}
运行结果: