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

 

 

 

 

 

posted @ 2021-10-10 16:23  天子骄龙  阅读(142)  评论(0编辑  收藏  举报