您的位置:首页 > 运维架构

图形的读取、转灰度图、显示、保存

2018-03-25 17:14 190 查看
#include<opencv2\imgproc\imgproc.hpp>
#include<opencv2\highgui\highgui.hpp>
using namespace cv;
int main() {
//读取图像
//Mat定义一个储存图像的空间
//imread为读取函数
Mat img = imread("H:\\city.jpg");
//判断图像读取是否成功
//img.empty()读取失败时返回1,成功时返回0.
if (img.empty()) {
printf("图片加载失败");
//按任意键退出
waitKey(0);
return 0;
}
Mat dst;
//将img转化为灰度图储存到dst中
cvtColor(img, dst, CV_BGR2GRAY);
//将dst保存
imwrite("H:\\hcity.jpg", dst);
//命名创建一个图像窗口
namedWindow("原图像",500);
//输出图像
imshow("原图像", img);
namedWindow("灰图像",500);
imshow("灰图像", dst);
//按任意键退出
waitKey(0);
//销毁窗口
destroyWindow("原图像");
destroyWindow("灰图像");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OpenCV基础