首页 > 代码库 > 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学习笔记——形态学梯度操作
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。