c语言将图像转化为灰度图像,并将灰度图像像素值存入二维数组

2025-03-10 06:53:14
推荐回答(1个)
回答1:

#include
#include
#include

int main(){
img = imread("./lena.png");
cvtColor(img, img, CV_BGR2GRAY);
uchar** pixmat = new uchar*[img.rows];
for(int i = 0; i < img.rows; i++){
pixmat[i] = new uchar[img.cols];
for(int j = 0; j < img.cols; j++){
pixmat[i][j] = img.at(i, j);
}}}
//pixmat is demanded 2-D array