首页 > 代码库 > OpenCV学习笔记——形态学梯度操作

OpenCV学习笔记——形态学梯度操作

代码:

#include<cv.h>#include<highgui.h>int main(void){	cvNamedWindow("cmp");	IplImage *temp = cvLoadImage("sample.jpg");//载入	IplImage *src = http://www.mamicode.com/cvCreateImage(CvSize(temp->width*0.5,temp->height*0.5), temp->depth,temp->nChannels);//缩放"open", CvPoint(20, 40), &font, CV_RGB(169, 55, 55));	cvPutText(close, "close", CvPoint(20, 40), &font, CV_RGB(169, 55, 55));	cvPutText(gradient, "gradient", CvPoint(20, 40), &font, CV_RGB(169, 55, 55));	cvPutText(tophat, "tophat", CvPoint(20, 40), &font, CV_RGB(169, 55, 55));	cvPutText(blackhat, "blackhat", CvPoint(20, 40), &font, CV_RGB(169, 55, 55));	int width = src->width;	int height = src->height;	cvSetImageROI(total, CvRect(0, 0, width, height));	cvCopy(open, total);	cvResetImageROI(total);	cvSetImageROI(total, CvRect(width, 0, width, height));	cvCopy(close, total);	cvResetImageROI(total);	cvSetImageROI(total, CvRect(width*2, 0, width, height));	cvCopy(gradient, total);	cvResetImageROI(total);	cvSetImageROI(total, CvRect(width * 3, 0, width, height));	cvCopy(tophat, total);	cvResetImageROI(total);	cvSetImageROI(total, CvRect(width * 4, 0, width, height));	cvCopy(blackhat, total);	cvResetImageROI(total);	cvShowImage("cmp", total);	cvWaitKey(0);	cvSaveImage("out.png", total);	cvDestroyAllWindows();	cvReleaseImage(&temp);	cvReleaseImage(&src);	cvReleaseImage(&srctemp);	cvReleaseImage(&total);	cvReleaseImage(&open);	cvReleaseImage(&close);	cvReleaseImage(&gradient);	cvReleaseImage(&tophat);	cvReleaseImage(&blackhat);	return 0;}

  

效果:
技术分享

OpenCV学习笔记——形态学梯度操作