其他分享
首页 > 其他分享> > opencv-saturate_cast防溢出函数

opencv-saturate_cast防溢出函数

作者:互联网

函数功能:当数据超过数据类型最大值时取最大值, 当数据小于数据类型最小值时取最小值

    uchar i=200;
    qDebug()<<i<<Qt::endl;  //i输出200
    i=cv::saturate_cast<uchar>(255);
    qDebug()<<i<<Qt::endl;  //i输出255
    i=cv::saturate_cast<uchar>(400);
    //返回值255,因为400超出uchar最大值255,所以取255
    qDebug()<<i<<Qt::endl;  //i输出255
    i=cv::saturate_cast<uchar>(-10);
    //返回值0,因为-10超出uchar最小值0,所以取0
    qDebug()<<i<<Qt::endl;  //i输出0

 

 

 

 

 

标签:cast,uchar,最大值,saturate,数据类型,opencv,最小值,qDebug,255
来源: https://www.cnblogs.com/liming19680104/p/15389743.html