1 读写图像
- imread:可以指定加载为灰度或者RGB图像
- imwrite:保存图像文件,类型由扩展名决定
2 读写像素
at(int y, int x)
方法
y表示行号、x表示列号。at是一个模板方法,使用时需要指定返回值的预期类型,如image.at<uchar>(j, i) = 255;
- 读一个GRAY像素点的像素值(CV_8UC1)
//方法1
Scalar intensity = img.at<Vec3b>(y, x);
//Vec3b是一种数据类型,表示3通道无符号类型的向量
//y表示行号,x表示列号
//方法2
Scalar intensity = img.at<uchar>(Point(x, y));
- 读一个BGR像素点的像素值
Vec3f intensity = img.at<Vec3b>(y, x);
float blue = intensity.val[0]; //取B分量
float green = intensity.val[1]; //取G分量
float red = intensity.val[2]; //取R分量
3 修改像素值
- 灰度图像
img.at<uchar>(y, x) = 128;
- RGB三通道图像
img.at<Vec3b>(y, x)[0] = 128; //blue
img.at<Vec3b