膨胀结果
原图像
膨胀处理后图像
Show me the code
#include <opencv2/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <string>
using namespace std;
int main() {
// 图像路径
const string FILENAME = "xxx.jpg";
// 读取图像
const cv::Mat origin = cv::imread(FILENAME);
// 设置膨胀窗大小,生成膨胀窗
const int winRow = 25;
const int winCol = 25;
cv::Mat element = cv::getStructuringElement(cv::MORPH_DILATE,
cv::Size(winCol, winRow));
//图像膨胀
cv::Mat result;
cv::dilate(origin,
result,
element);
//显示原图和膨胀结果
cv::imshow("Origin Image", origin);
cv::imshow("Result", result);
cv::waitKey(0);
}