Opencv C++成长之路(十):图像腐蚀
腐蚀结果
原图像
腐蚀处理后图像
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_ERODE,
cv::Size(winCol, winRow));
//图像腐蚀
cv::Mat result;
cv::erode(origin,
result,
element);
//显示原图和腐蚀结果
cv::imshow("Origin Image", origin);
cv::imshow("Result", result);
cv::waitKey(0);
}