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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM