1、图像操作。
(1)、读写图像
(2)、读写像素
(3)、修改像素
2、读写图像
(1)、imread 可以指定加载为灰度或者RGB图像
(2)、imwrite 保存图像文件,类型由扩展名决定
3、读写像素
(1)、读一个GRAY像素点的像素值(CV_8UC1)Scalar intensity = img.at<uchar>(y, x); 或者 Scalar intensity = img.at<uchar>(Point(x, y));
(2)、读一个RGB像素点的像素值
Vec3f intensity = img.at<Vec3f>(y, x);
float blue = intensity.val[0];
float green = intensity.val[1];
float red = intensity.val[2];
4、修改像素值
(1)、灰度图像
img.at<uchar>(y, x) = 128;
(2)、三通道图像
img.at<Vec3b>(y,x)[0]=128; // blue
img.at<Vec3b>(y,x)[1]=128; // green
img.at<Vec3b>(y,x)[2]=128; // red
(3)、空白图像赋值
img = Scalar(0);
(4)、I选择
Rect r(10, 10, 100, 100);
Mat smallImg = img(r);
5、Vec3b与Vec3F
(1)、Vec3b对应三通道的顺序是blue、green、red的uchar类型数据。
(2)、Vec3f对应三通道的float类型数据
(3)、把CV_8UC1转换到CV32F1实现如下:
src.convertTo(dst, CV_32F);