OpenCV morphologyEx, getStructuringElement function example source


This is example source code.


Mat img;
img = imread("moSample.jpg");

Mat element = getStructuringElement(MORPH_RECT, Size(3, 3), Point(1,1) );
Mat rImg;
morphologyEx(img, rImg, CV_MOP_CLOSE, element);
//morphologyEx(img, img, CV_MOP_CLOSE, element); -> It is also ok.

namedWindow("i");
imshow("i",img);
namedWindow("r");
imshow("r",rImg);
cvWaitKey(0);


In here
We can set filter box size and center point using getStructuringElement function.
-first parameter has
MORPH_RECT, MORPH_CROSS, MORPH_ELLIPSE
They show the shape of the filter box.

-second parameter means size of box.
-third parameter means center point of the box.

This picture is result of morphology processing.
using 9x9 box size /  4,4 center



Thank you.

Comments

Popular posts from this blog

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

OpenCV Stitching example (Stitcher class, Panorama)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

Optical Flow sample source code using OpenCV

OpenCV Drawing Example, (line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours)

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

SICK LMS511 sensor data acquisition interface (source code, C++/MFC)

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Image warping (using opencv findHomography, warpPerspective)