1.主要内容
- 读写图像
- 读写像素
- 修改像素值
2.读写图像
imread 可以指定加载为灰度或者RGB图像
imwrite 保存图像文件,类型由扩展名决定
3.读写像素
读一个GRAY像素点的像素值(CV_8UC1)
Scalar intensity = img.at<uchar>(y, x);
或者
Scalar intensity = img.at<uchar>(Point(x, y));
读一个RGB像素点的像素值
Vec3f intensity = img.at<Vec3f>(y, x);
float blue = intensity.val[0];
float green = intensity.val[1];
float red = intensity.val[2];
4.修改像素值
灰度图像
img.at<uchar>(y, x) = 128;
RGB三通道图像
img.at<Vec3b>(y,x)[0]=128; // blue
img.at<Vec3b>(y,x)[1]=128; // green
img.at<Vec3b>(y,x)[2]=128; // red
空白图像赋值
img = Scalar(0);
ROI选择
Rect r(10, 10, 100, 100);
Mat smallImg = img(r);
5.Vec3b与Vec3F
Vec3b对应三通道的顺序是blue、green、red的uchar类型数据。
Vec3f对应三通道的float类型数据
把CV_8UC1转换到CV32F1实现如下:
src.convertTo(dst, CV_32F);
6.课外扩展:
OpenCv中向量模板类Vec的表示
https://blog.csdn.net/mangobar/article/details/82863558
ROI(region of interest)百度百科
https://baike.baidu.com/item/ROI/1125333?fr=aladdin
图像的ROI区域选择与复制
https://www.cnblogs.com/nicewe/p/8461994.html
range()函数用法
https://blog.csdn.net/u011973222/article/details/79929366
sobel函数
https://blog.csdn.net/qq_18343569/article/details/47835679
opencv入门笔记at的用法
https://blog.csdn.net/visionfuture/article/details/77092695
像素值的读写opencv的at函数
https://blog.csdn.net/qq_36503007/article/details/79895610
opencv笔记——OpenCV轮廓vector
https://blog.csdn.net/qq_37764129/article/details/82142400
C++/opencv学习笔记(Vector用法)
https://blog.csdn.net/Zouziceng/article/details/78052203
opencv3::Mat元素的获取、at,ptr
https://blog.csdn.net/BoaHock/article/details/80790323
opencv MAT中维度(dims)和通道(channels)的理解和区别
https://blog.csdn.net/chengde6896383/article/details/83444874
opencv学习(十六)之颜色空间转换cvtColor()
https://blog.csdn.net/keith_bb/article/details/53470170
OpenCV之bitwise_and、bitwise_not等图像基本运算及掩膜
https://blog.csdn.net/u011028345/article/details/77278467