• Opencv3 图片膨胀与腐蚀


    #include <iostream>
    #include <opencv2/opencv.hpp>

    using namespace std;
    using namespace cv;

    int elementSize = 3;
    int maxSize = 260;

    int Demo_Load_Img();

    //图片膨胀
    void Get_Img_Struct_Element_Dilate(int, void*);

    //图片腐蚀
    void Get_Img_Struct_Element_Erode(int, void*);

    Mat img1, img2, structElement;
    char win1[] = "window1";
    char win2[] = "window2";

    int Demo_Load_Img()
    {
      img1 = imread("D://images//4.jpg");
      imshow(win1,img1);
      //图片膨胀
      //createTrackbar("Element Size:",win1,&elementSize,maxSize, Get_Img_Struct_Element_Dilate);
      ////图片膨胀
      //Get_Img_Struct_Element_Dilate(0,0);

      //图片腐蚀
      createTrackbar("Element Size:", win1, &elementSize, maxSize, Get_Img_Struct_Element_Erode);
      //图片腐蚀
      Get_Img_Struct_Element_Erode(0, 0);


      return 0;
    }

    //图片膨胀
    void Get_Img_Struct_Element_Dilate(int,void*)
    {
      int size_1 = elementSize * 2 + 1;
      structElement = getStructuringElement(MORPH_RECT,Size(size_1,size_1),Point(-1,-1));
      //膨胀
      dilate(img1,img2,structElement,Point(-1,-1),1);
      imshow(win2,img2);
    }

    void Get_Img_Struct_Element_Erode(int,void*)
    {
      int size_1 = elementSize * 2 + 1;
      structElement = getStructuringElement(MORPH_RECT, Size(size_1, size_1), Point(-1, -1));
      //腐蚀
      erode(img1, img2, structElement);
      imshow(win2, img2);
    }

    int main()
    {
      Demo_Load_Img();


      waitKey(0);
      return 0;
    }

  • 相关阅读:
    IDETalk
    servlet概述
    过滤器(Filter)
    ieda常用快捷键
    UUID
    JRebel 7.0.10 for intellij IDEA 2017.1
    BP神经网络(手写数字识别)
    遗传算法解决TSP问题
    [CODEVS1258]关路灯
    [NOIP2007]统计数字
  • 原文地址:https://www.cnblogs.com/herd/p/9734041.html
Copyright © 2020-2023  润新知