码迷,mamicode.com
首页 > 其他好文 > 详细

opencv:二值图像的概念

时间:2020-02-14 00:55:14      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:wait   show   char   char*   png   opencv2   binary   clu   cpp   

灰度图像与二值图像

技术图片

二值分割

技术图片

#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!\n");
        return -1;
    }

    namedWindow("input", WINDOW_AUTOSIZE);
    imshow("input", src);

    Mat gray, binary;
    cvtColor(src, gray, COLOR_BGR2GRAY);
    imshow("gray", gray);

    threshold(gray, binary, 127, 255, THRESH_BINARY);
    imshow("binary", binary);

    threshold(gray, binary, 127, 255, THRESH_BINARY_INV);
    imshow("binary invert", binary);

    threshold(gray, binary, 127, 255, THRESH_TRUNC);
    imshow("binary trunc", binary);

    threshold(gray, binary, 127, 255, THRESH_TOZERO);
    imshow("binary to zero", binary);

    threshold(gray, binary, 127, 255, THRESH_TOZERO_INV);
    imshow("binary to zero invert", binary);


    waitKey(0);
    destroyAllWindows();

    return 0;
}

opencv:二值图像的概念

标签:wait   show   char   char*   png   opencv2   binary   clu   cpp   

原文地址:https://www.cnblogs.com/wbyixx/p/12305849.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!