• opencv形态学操作


    main.cpp

    #include <istream>
    #include <opencv2/opencv.hpp>
    
    using namespace cv;
    using namespace std;
    
    
    int main(int argc, char **argv) {
        Mat src, open_dst, close_dst, gradient_dst, top_hat_dst, black_hat_dst, dilate_dst, erode_dst, hit_miss_dst;
        //    加载图片
        src = imread("../../picture/bg1.webp", 1);
        if (!src.data) {
            printf("No image data \n");
            return -1;
        }
        char src_title[] = "src";
        namedWindow(src_title, WINDOW_AUTOSIZE);
        imshow(src_title, src);
        // 形态学开操作
        char open_title[] = "open";
        namedWindow(open_title, WINDOW_AUTOSIZE);
        Mat open_kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
        morphologyEx(src, open_dst, MORPH_OPEN, open_kernel);
        imshow(open_title, open_dst);
    
        // 形态学关操作
        char close_title[] = "close";
        namedWindow(close_title, WINDOW_AUTOSIZE);
        Mat close_kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
        morphologyEx(src, close_dst, MORPH_CLOSE, close_kernel);
        imshow(close_title, close_dst);
    
        // 形态学梯度操作
        char gradient_title[] = "gradient";
        namedWindow(gradient_title, WINDOW_AUTOSIZE);
        Mat gradient_kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
        morphologyEx(src, gradient_dst, MORPH_GRADIENT, gradient_kernel);
        imshow(gradient_title, gradient_dst);
    
        // 形态学顶帽操作
        char top_hat_title[] = "top_hat";
        namedWindow(top_hat_title, WINDOW_AUTOSIZE);
        Mat top_hat_kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
        morphologyEx(src, top_hat_dst, MORPH_TOPHAT, top_hat_kernel);
        imshow(top_hat_title, top_hat_dst);
    
        // 形态学黑帽操作
        char black_hat_title[] = "black_hat";
        namedWindow(black_hat_title, WINDOW_AUTOSIZE);
        Mat black_hat_kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
        morphologyEx(src, black_hat_dst, MORPH_BLACKHAT, black_hat_kernel);
        imshow(black_hat_title, black_hat_dst);
    
        // 形态学膨胀操作
        char dilate_title[] = "dilate";
        namedWindow(dilate_title, WINDOW_AUTOSIZE);
        Mat dilate_kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
        morphologyEx(src, dilate_dst, MORPH_DILATE, dilate_kernel);
        imshow(dilate_title, dilate_dst);
    
        // 形态学腐蚀操作
        char erode_title[] = "erode";
        namedWindow(erode_title, WINDOW_AUTOSIZE);
        Mat erode_kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
        morphologyEx(src, erode_dst, MORPH_ERODE, dilate_kernel);
        imshow(erode_title, erode_dst);
    
        //    等待按键
        waitKey(0);
        return 0;
    }
    

      

  • 相关阅读:
    python学习第十一天 -- 函数式编程
    python学习第十天 -- 函数
    python学习第九天 -- 列表生产式
    python学习第八天 -- 迭代
    (转载)C# 编程 使用可空类型
    Func的介绍——c#封装的代理
    select SCOPE_IDENTITY()用法
    insert into 语句的三种写法
    面试感悟----一名3年工作经验的程序员应该具备的技能
    SQL中常用模糊查询的四种匹配模式&&正则表达式
  • 原文地址:https://www.cnblogs.com/navysummer/p/16314343.html
Copyright © 2020-2023  润新知