zoukankan      html  css  js  c++  java
  • opencv:全局阈值

    图像的二值化分割,最重要的就是计算阈值

    阈值的计算方法很多,基本分为两类,全局阈值与自适应阈值

    OTSU、Triangle




    #include <opencv2/opencv.hpp>
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    
    
    int main(int argc, char** argv)
    {
        Mat src = imread("f:/images/shuang001.jpg");
        if (src.empty())
        {
            printf("Could not find the image!
    ");
            return -1;
        }
    
        namedWindow("input", WINDOW_AUTOSIZE);
        imshow("input", src);
    
        Mat gray, binary;
        cvtColor(src, gray, COLOR_BGR2GRAY);
        imshow("gray", gray);
    
        // 均值分割
        Scalar m = mean(gray);
        printf("means: %.2f
    ", m[0]);
        threshold(gray, binary, m[0], 255, THRESH_BINARY);
        imshow("binary", binary);
    
        // 直方图
        threshold(gray, binary, 0, 255, THRESH_BINARY | THRESH_OTSU);
        imshow("THRESH_OTSU", binary);
    
        threshold(gray, binary, 0, 255, THRESH_BINARY | THRESH_TRIANGLE);
        imshow("THRESH_TRIANGLE", binary);
    
        waitKey(0);
        destroyAllWindows();
    
        return 0;
    }
    
  • 相关阅读:
    VMware虚拟机安装
    代码搜索的终极武器Ag
    模糊搜索神器fzf
    Python:json、xml、字典各种转换
    03-azkaban安装部署
    linux下环境变量PATH设置错误的补救
    01-编译azkaban
    VMware安装CentOS7
    PS(二)
    等待公交车的时间
  • 原文地址:https://www.cnblogs.com/wbyixx/p/12313675.html
Copyright © 2011-2022 走看看