opencv函数学习:convertTo()的使用
convertTo()
void cv::Mat::convertTo(OutputArray m, int rtype, double alpha = 1
, double beta = 0
) const
Converts an array to another data type with optional scaling. —— 该函数主要用于数据类型的相互转换
The method converts source pixel values to the target data type. saturate_cast<> is applied at the end to avoid possible overflows:
m(x,y)=saturate_cast<rType>(α(∗this)(x,y)+β) —— 这是函数底层算法,了解算法后方便我们熟练运用
- Parameters
-
m output matrix; if it does not have a proper size or type before the operation, it is reallocated. rtype desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input. alpha optional scale factor. beta optional delta added to the scaled values. 例子:将16位图像数据转为8位
Mat dstImg;
Mat srcImg(w, h, CV_16UC1, img);
srcImg.convertTo(dstImg, CV_8CU1, 255.0/65535, 0.5);
分类:
opencv
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· 单线程的Redis速度为什么快?
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码