标签:
在边缘检测算法中Canny颇为经典,我们就来做一下测试,并且顺便实现图像的尺寸放缩。
直接执行程序得到结果如下:将载入图像显示在窗口in内,同时进行图像两次缩小一半操作将结果显示到i1,i2窗口内,Canny边缘提取结果显示在i3。
#include "stdafx.h" #include"cv.h" #include"highgui.h" /* 定义图像放缩函数doPyrDown(原图像,高斯5*5滤波器) */ IplImage* doPyrDown(IplImage* in,int filter = CV_GAUSSIAN_5x5) { IplImage* out = cvCreateImage(cvSize(in->width/2,in->height/2),in->depth,in->nChannels); /*使用Gaussian金字塔分解输入图像向下采样*/ /*首先该函数与内核卷积,然后向下采样删除偶数行列信息*/ cvPyrDown(in,out); return(out); }; /* 定义边缘检测函数doCanny(原图像,若边缘连接阈值,强边缘分割阈值,索贝尔算子内核尺寸) */ IplImage* doCanny(IplImage* in,double lowThresh,double highThresh,double aperture) { if(in->nChannels != 1)//仅支持单通道图像 return(0); IplImage* out = cvCreateImage(cvGetSize(in),IPL_DEPTH_8U,1); //找输入图像的边缘并输出图像中标识着这些边缘 cvCanny(in ,out,lowThresh,highThresh,aperture); return(out); }; int _tmain(int argc, _TCHAR* argv[]) { IplImage* in = cvLoadImage("lena.jpg",0); //载入原图像 IplImage* img1 = doPyrDown( in, CV_GAUSSIAN_5x5);//图像尺寸缩小一半 IplImage* img2 = doPyrDown(img1,CV_GAUSSIAN_5x5);//继续缩小一半 IplImage* img3 = doCanny(img2,10,100,3);//边缘检测 cvNamedWindow("in"); cvNamedWindow("i1"); cvNamedWindow("i2"); cvNamedWindow("i3"); cvShowImage("in",in); cvShowImage("i1",img1); cvShowImage("i2",img2); cvShowImage("i3",img3); cvWaitKey(0); cvDestroyWindow("in"); cvDestroyWindow("i1"); cvDestroyWindow("i2"); cvDestroyWindow("i3"); return 0; }
Canny边缘检测及图像缩放之图像处理算法-OpenCV应用学习笔记四
标签:
原文地址:http://www.cnblogs.com/Fireburning-tec/p/5146412.html