Opencv provides a common morphological function cvmorphologyex, which can be used to perform on-demand operations, close operations, form gradients, gift hat operations, and black hat operations. The example is as follows:
# Include "stdafx. H "# include" CV. H "# include" highgui. H "# include" highgui. H "int main (INT argc, char ** argv) {cvnamedwindow (" sourceimage "); cvnamedwindow (" open "); cvnamedwindow (" close "); cvnamedwindow ("gradient"); cvnamedwindow ("tophat"); cvnamedwindow ("blackhat"); iplimage * src = cvloadimage ("test.bmp"); cvshowimage ("sourceimage ", SRC); iplimage * temp = cvcreateimage (cvgetsize (SRC), 8, 3); iplimage * IMG = cvcreateimage (cvgetsize (SRC), 8, 3); cvcopyimage (SRC, temp ); cvcopyimage (SRC, IMG); // cvmorphologyex (SRC, IMG, temp, null, // default 3*3 cv_mop_open, 4); cvshowimage ("open ", IMG); // closed cvmorphologyex (SRC, IMG, temp, null, // default 3*3 cv_mop_close, 4); cvshowimage ("close", IMG ); // morphological gradient cvmorphologyex (SRC, IMG, temp, null, // default 3*3 cv_mop_gradient, 3); cvshowimage ("gradient", IMG ); // cvwaitkey (0); // "gift hat" cvmorphologyex (SRC, IMG, temp, null, // default 3*3 cv_mop_tophat, 3); cvshowimage ("tophat ", IMG); // cvwaitkey (0); // "Black Hat" cvmorphologyex (SRC, IMG, temp, null, // default 3*3 cv_mop_blackhat, 3 ); cvshowimage ("blackhat", IMG); cvwaitkey (0); cvreleaseimage (& temp); cvreleaseimage (& SRC); cvreleaseimage (& IMG); cvdestroyallwindows (); Return 0 ;}
The running result is:
References:
1. Learning opencv, Yu Shiqi, Liu Rui, Tsinghua University Press, pp.139-145.
2. http://www710.univ-lyon1.fr /~ Bouakaz/OpenCV-0.9.5/docs/Ref/opencvref_imageprocessing.htm
3. http://www710.univ-lyon1.fr /~ Bouakaz/OpenCV-0.9.5/docs/Ref/opencvref_imageprocessing.htm