OpenCV/第5章 图像开和闭操作 //author: rorger //time: 2010-10-20 21:25:41 图形形态学之开运算和闭运算: 开运算:去除较小的明亮区域 闭运算:消除低亮度值的孤立点 #include "cv.h" #include "highgui.h" #include "highgui.h" int main(int argc, char ** argv) { cvNamedWindow("image"); IplImage * src = cvLoadImage(argv[1], 0); IplImage * temp = cvCreateImage(cvGetSize(src), 8,1); IplImage * img=cvCreateImage(cvGetSize(src), 8, 1); cvCopyImage(src,temp); cvCopyImage(src, img); //开运算 cvMorphologyEx( src, img, temp, NULL, //default 3*3 CV_MOP_OPEN, 1); cvShowImage("image", img); cvWaitKey(0); //闭运算 cvMorphologyEx( src, img, temp, NULL, //default 3*3 CV_MOP_CLOSE, 1); cvShowImage("image", img); cvWaitKey(0); cvReleaseImage(&temp); cvReleaseImage(&src); cvReleaseImage(&img); cvDestroyAllWindows(); return 0; }