zoukankan      html  css  js  c++  java
  • opencv:自适应阈值



    #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);
    
        // 自适应阈值二值化
        adaptiveThreshold(gray, binary, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 25, 10);
        imshow("ADAPTIVE_THRESH_GAUSSIAN_C ", binary);
    
        adaptiveThreshold(gray, binary, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 25, 10);
        imshow("ADAPTIVE_THRESH_MEAN_C ", binary);
    
        waitKey(0);
        destroyAllWindows();
    
        return 0;
    }
    
  • 相关阅读:
    js-js系列-数据类型-概念
    js-基础总结3
    js-基础总结2
    js-基础总结1
    js-面试题
    webpack-模块化
    js-对象常用方法
    js-事件冒泡-事件捕获-事件委托
    js-call aplly bind2
    aioxs实现token无感刷新
  • 原文地址:https://www.cnblogs.com/wbyixx/p/12313746.html
Copyright © 2011-2022 走看看