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

  • 相关阅读:
    easyui 如何引入
    图片切换展示效果
    渐变弹出层
    C# GEP基因化编程
    C#操作内存
    移动的彩虹
    收缩和展开效果
    用SQL语句,删除掉重复项只保留一条
    图片切换,带标题文字
    Sql Server快速建表
  • 原文地址:https://www.cnblogs.com/IAMSailorMoon/p/14372228.html
Copyright © 2011-2022 走看看