随笔 - 37  文章 - 0  评论 - 0  阅读 - 62346

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);

posted on   Cynthia_W  阅读(3136)  评论(0编辑  收藏  举报
编辑推荐:
· 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,欢迎大家贡献代码
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示