Opencv腐蚀-erode函数

时间:2021-02-02 20:01:36
#include<iostream>
#include<opencv2/opencv.hpp>

using namespace std;
using namespace cv;

Mat srcImage, dstImage;
int g_nErodeValue = 0;

//有滚动条事件时,可以进入回调函数
void on_Trackbar(int, void *)
{
Mat element = getStructuringElement(MORPH_RECT, Size(2 * g_nErodeValue + 1, 2 * g_nErodeValue + 1));
erode(srcImage, dstImage, element);
imshow("【腐蚀窗口】", dstImage);
}

int main()
{
srcImage = imread("tiger.jpg");
imshow("【原图】", srcImage);
dstImage.create(srcImage.size(), srcImage.type());

namedWindow("【腐蚀窗口】");
createTrackbar("Value", "【腐蚀窗口】", &g_nErodeValue, 100, on_Trackbar);
on_Trackbar(g_nErodeValue, 0);

waitKey(0);

return 0;
}

Opencv腐蚀-erode函数