getStructuringElement 原型:
Mat getStructuringElement(int shape, //核的形状 0:矩形 1:十字交叉形 2: 椭圆
Size ksize,//核大小
Point anchor=Point(-1,-1) //核中心位置,默认位于形状中心处
);
#include "core/core.hpp"
#include "highgui/highgui.hpp"
#include "imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
int main(int argc,char *argv[])
{
Mat elementRect,elementCross,elementEllipse;
elementRect=getStructuringElement(MORPH_RECT,Size(3,3),Point(-1,-1));
elementCross=getStructuringElement(MORPH_CROSS,Size(3,3),Point(-1,-1));
elementEllipse=getStructuringElement(MORPH_ELLIPSE,Size(3,5),Point(-1,-1));
std::cout<<"3*3矩形核:"<<std::endl<<elementRect<<std::endl;
std::cout<<"3*3十字叉形核:"<<std::endl<<elementCross<<std::endl;
std::cout<<"3*3椭圆形核:"<<std::endl<<elementEllipse<<std::endl;
system("pause");
}
#include "core/core.hpp"
#include "highgui/highgui.hpp"
#include "imgproc/imgproc.hpp"
using namespace cv;
int main(int argc,char *argv[])
{
Mat image,imageGray,imageDilate,imageErode,imageBorder;
image=imread(argv[1]);
resize(image,image,Size(400,400));
cvtColor(image,imageGray,CV_RGB2GRAY);
//enum { MORPH_RECT=0, MORPH_CROSS=1, MORPH_ELLIPSE=2 };
Mat element=getStructuringElement(1,Size(3,3),Point(-1,-1));
dilate(imageGray,imageDilate,element,Point(-1,-1));
erode(imageGray,imageErode,element,Point(-1,-1));
imageBorder=imageDilate-imageErode;
imshow("Source image",image);
imshow("Dilate",imageDilate);
imshow("Erode",imageErode);
imshow("Border",imageBorder);
waitKey();
}