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

  • 相关阅读:
    记录输出时间
    ***灵感或者没想到的思想
    Managing Difficulties
    4.20
    单调队列
    背包
    线性DP
    可持久化数据结构
    平衡树
    点分治
  • 原文地址:https://www.cnblogs.com/IAMSailorMoon/p/14372228.html
Copyright © 2011-2022 走看看