The code is as follows:
#include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp > #include <opencv2/imgproc/imgproc.hpp>using namespace cv;int main () { Mat src = imread ("Lena.jpg", 0); Mat DST, close, open; Mat Element (5, 5, cv_8u, Scalar (1)); Threshold (SRC, DST, 255, THRESH_BINARY_INV); Namedwindow ("DST", 0); Imshow ("DST", DST); Morphologyex (DST, close, morph_close, Element);//closed Operation Namedwindow ("Close", 0); Imshow ("Close", close); Morphologyex (DST, open, morph_open, Element);//Open Operation Namedwindow ("open", 0); Imshow ("Open", open); Waitkey (0);}
Function Description:
1, Morphologyex function in fact, with the use of corrosion and expansion of the same, the definition of closed operation on the image line expansion and corrosion, open operation is the opposite.
Closed operation: It is used to fill a small cavity inside an object, to connect adjacent objects, to smooth its boundary without significantly altering its area.
Open operation: It is used to eliminate small objects, to separate objects at slender points, to smooth the boundaries of larger objects without significantly altering their area.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Development of OpenCV 2.4.11 under Qt 5.3 (14) open and closed operations