一、读写图像
imread 可以指定加载为灰度或者RGB图像
Imwrite 保存图像文件,类型由扩展名决定
具体内容参照以前的博客:https://blog.csdn.net/qq_38236355/article/details/88969483
二、读写像素
读一个GRAY像素点(单通道)的像素值(CV_8UC1):
Scalar intensity = img.at<uchar>(row, col);
或者Scalar intensity = img.at<uchar>(y, x);
或者 Scalar intensity = img.at<uchar>(Point(x, y));
这里说明一下一个像素点的坐标(x,y)分别对应它所在图像的列和行(col,row)。
读一个RGB像素点(三通道)的像素值:
Vec3f intensity = img.at<Vec3f>(y, x);
float blue = intensity.val[0];
float green = intensity.val[1];
float red = intensity.val[2];
等价于:
float blue = img.at<Vec3f>(y,x)[0];
float green = img.at<Vec3f>(y,x)[1];
float red = img.at<Vec3f>(y,x)[2];
具体<>中应填写什么类型,是由图像img的类型决定