发布时间:2023-08-01 14:00
本文详细介绍基于opencv的彩色图像到灰度图像的转换和图像的保存
首先介绍要用到的两个关键的opencv函数,cvtColor(InputArray src, OutputArray dst, int code, int dstCn = 0) 和imwrite(const String & filename,InputArray img, const std::vector
cvtColor(InputArray src, OutputArray dst, int code, int dstCn = 0):
InputArray src: 输入图像即要进行颜色空间变换的原图像,可以是Mat类
OutputArray dst: 输出图像即进行颜色空间变换后存储图像,也可以Mat类
int code: 转换的代码或标识,即在此确定将什么制式的图片转换成什么制式的图片,
int dstCn = 0: 目标图像通道数,如果取值为0,则由src和code决定
imwrite(const String &filename, InputArrary img, const std:vector
filename:需要保存图像的文件名,要保存图片为哪种格式,就带什么后缀。
img:要保存的图像。
params:表示为特定格式保存的参数编码。
完整代码如下:
#include
#include
using namespace cv;
using namespace std;
void main()
{
Mat image;
Mat imgGray;
image = imread("lena.jpg");//根据自己图像路径填写,此代码默认当前文件夹
cvtColor(image, imgGray, CV_BGR2GRAY);
namedWindow("image", WINDOW_NORMAL);
imshow("image", imgGray);
imwrite("result.jpg", imgGray);//根据自己图像路径填写,此代码默认当前文件夹
waitKey();
}
下图为结果图
原图 灰度图
灰度图像将会保存到了指定文件夹
使用SpringBoot一小时快速搭建一个简单后台管理(增删改查)(超详细教程)
dynamic + shardingsphere(4.1.1) 实现动态分库分表
论文解读(IGSD)《Iterative Graph Self-Distillation》
Visual Attention Network(VAN)算法分析
4.2 APP_UI ----Appium工具介绍以及元素定位
ElasticSearch+Kibana+Logstash实现日志可视化运维监控
k折交叉验证法python实现_使用python+sklearn实现使用K均值进行颜色量化
机器翻译自动评价之BLEU详解-BLEU: a Method for Automatic Evaluation of Machine Translation