• OpenCV使用阈值截断实现二值分割(黑白图)


    一、概述

      二值化比较简单,具体步骤如下:

      1.将输入图像转为灰度图

      2.执行二值化(再这之前也可以去除噪声,视情况而定)

      3.执行输出

    二、代码  

    /**
     * 对图像进行二值分割
     * @param inputImagePath
     */
    void showThresholdImage(char *inputImagePath) {
        Mat src = imread(inputImagePath);
        Mat gray;
        //灰度图
        cvtColor(src, gray, COLOR_BGR2GRAY);
        //对图像进行二值分割
        Mat result;
        threshold(gray, result, 140, 255, THRESH_BINARY);
        imshow("src", src);
        waitKey(0);
        imshow("threshold", result);
        waitKey(0);
    }

    三、对比图

  • 相关阅读:
    爬虫基础 2.1 http原理
    爬虫基础 2.1 http原理
    3.29上午
    3.28
    3.27下午
    3.27上午
    3.24上午
    3.23下午
    3.23上午
    3.22上午
  • 原文地址:https://www.cnblogs.com/tony-yang-flutter/p/14845817.html
Copyright © 2020-2023  润新知