C++ OpenCV 获取灰度图像矩阵数据示例
#include <opencv2/opencv.hpp>
#include
using namespace cv; using namespace std;
int main() { Mat img_gray = imread('lena_gray.jpg', IMREAD_GRAYSCALE); // 读取灰度图像
int rows = img_gray.rows; // 获取行数
int cols = img_gray.cols; // 获取列数
for(int i=0; i<rows; i++)
{
for(int j=0; j<cols; j++)
{
uchar pixel = img_gray.at<uchar>(i,j); // 获取像素值
cout << (int)pixel << ' '; // 输出像素值
}
cout << endl;
}
return 0;
}
AI 优化版
原文地址:https://www.cveoy.top/t/topic/lWTI 著作权归作者所有。请勿转载和采集!