zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    PAT 1025. 反转链表 (25)
    PAT 1024. 科学计数法 (20)
    PAT 1076. Forwards on Weibo (30)
    C++——cout输出小数点后指定位数
    PTA 06-图3 六度空间 (30分)
    PTA 06-图2 Saving James Bond
    PTA
    浙大PTA
    浙大PTA
    随机密码生成
  • 原文地址:https://www.cnblogs.com/IAMSailorMoon/p/14372228.html
Copyright © 2011-2022 走看看