【OpenCV 2.4.9 用户指南之一】图像读写、显示、基本操作
来源:互联网 发布:知乐百度网盘 编辑:程序博客网 时间:2024/04/30 22:41
读图像
Mat img = imread ( filename ); 默认3通道
Mat img = imread(filename,0); 加载灰度图
写图像
imwrite(filename, img);
读取灰度图像元值
Scalar intensity = img.at<uchar>(y, x); 矩阵形式,先行后列
或Scalar intensity = img.at<uchar>(Point(x,y)); 坐标形式
读取3波段图像像元值
Vec3b intensity =img.at<Vec3b>(y, x);
uchar blue = intensity.val[0];
uchar green= intensity.val[1];
uchar red = intensity.val[2];
<span style="font-family:Arial;">Vec3b intensity =img.at<Vec3b>(y, x);uchar blue = intensity.val[0];uchar green= intensity.val[1];uchar red = intensity.val[2];</span>
读取浮点型3波段图像像元值
Vec3f intensity = img.at<Vec3f>(y, x);
float blue = intensity.val[0];
float green = intensity.val[1];
float red = intensity.val[2];
改变像元值
img.at<uchar>(y, x) = 128;
calib3b模块中有函数,读写2维或3维点形成Mat格式矩阵。此矩阵为1列,每行代表1个点。
vector<point2f> points;
Mat pointsMat = Mat(points);
读取值
Point2f point = pointsMat.at<Point2f>(i, 0);
基本操作
从已有灰度图像中创建全黑图像
img = Scalar(0);
选择感兴趣区
Rect r(10,10,100,100);
Mat smallImg= img(r);
从Mat转为C接口数据结构
Mat img = imread("image.jpg");
IplImage img1 = img;
CvMat m = img;
注意:此处并无数据拷贝,只是拷贝了文件头,指向同一数据
从彩色图转为灰度图
Mat img = imread("image.jpg");
Mat grey;
cvtColor(img, grey, CVBGR2GRAY);
改变图像数据类型
src.convertTo(dst, CV_32F);
图形可视化
显示8U图像
Mat img = imread("img.jpg");
namedWindow ("image",CV_WINDOW_AUTOSIZE);
imshow("image",img);
waitKey();
32F图像转为8U图像
Mat img = imread("image.jpg");
Mat grey;
cvtColor(img,grey, CV_BGR2GRAY);
Mat sobelx;
Sobel(grey, sobelx,CV_32F,1,0);
double minVal,maxVal;
minMaxLoc(sobelx, &minVal, &maxVal); //找最小值和最大值
Mat draw;
sobelx.convertTo(draw,CV_8U, 255.0/(maxVal - minVal), -minVal * 255.0/(maxVal - minVal));
namedWindow("image",CV_WINDOW_AUTOSIZE);
imshow("image",draw);
waitKey();
- 【OpenCV 2.4.9 用户指南之一】图像读写、显示、基本操作
- opencv(9)---图像基本操作
- OpenCV用户指南——操作图像
- opencv基本图像操作
- opencv图像基本操作
- opencv-图像基本操作
- OpenCV-图像基本操作
- opencv图像处理基本操作
- OpenCV之图像基本操作
- OPencv图像处理基本操作
- opencv图像基本操作算法
- OpenCV-图像的基本操作
- opencv图像处理基本操作
- opencv(c++)-图像基本操作
- 一、opencv的图像基本读写
- OpenCV学习篇之一 显示图像
- OpenCV学习篇之一 显示图像
- opencv-图像处理1 图像基本操作
- JavaScript强化教程——jQuery - 获得内容和属性
- 解决VC6.0打开文件崩溃问题
- Codeforces Round #368 (Div. 2)
- String 转 Enum 对象关键字 Java
- ubuntu 14.04 64bit Qt5.4.2 Android error:Android build platform: android--1
- 【OpenCV 2.4.9 用户指南之一】图像读写、显示、基本操作
- Oracle BIEE 11G 嵌入Iframe
- Eclipse +Tomcat配置JNDI数据源
- Android 中门磁自动警报实例总结。。。。
- abap 知识点总结
- Acperience
- 【nyoj 1291 ABS 】
- [ATL/WTL]_[初级]_[Windows消息循环初解]
- osgearth学习之一 类库介绍