学习openCV|【学习opencv】对图像缩放并进行边缘检测

首先对图像进行缩放:
用到的函数:cvPyrDown(); 下面函数返回缩放后的图像
【学习openCV|【学习opencv】对图像缩放并进行边缘检测】

IplImage* doPyrDown(IplImage* in,int filter = IPL_GAUSSIAN_5x5) { assert( in->width%2 == 0 && in->height%2 == 0 ); IplImage* out = cvCreateImage( cvSize( in->width/2, in->height/2 ), in->depth, in->nChannels ); cvPyrDown( in, out ); //使用Gaussian金字塔分解对输入图像向下采样,输出图像的宽度和高度是输入图像的一半 return( out ); }; int main( int argc, char** argv ) { const char* cNamesmooth="smooth.jpg"; IplImage* img = cvLoadImage( cNamesmooth); IplImage* img2 = cvCreateImage( cvSize( img->width/2,img->height/2 ), img->depth, img->nChannels); cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE ); cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE ); cvShowImage("Example1", img ); img2 = doPyrDown( img ); cvShowImage("Example2", img2 ); cvWaitKey(0); cvReleaseImage( &img ); cvReleaseImage( &img2 ); cvDestroyWindow("Example1"); cvDestroyWindow("Example2"); }

边缘检测使用了Canny边缘检测:
IplImage* doCanny( IplImage* in,doublelowThresh, double highThresh,doubleaperture) { if (in->nChannels != 1) return(0); // Canny only handles gray scale images IplImage* out = cvCreateImage(cvGetSize( in ),in->depth, //IPL_DEPTH_8U, 1); cvCanny( in, out, lowThresh, highThresh, aperture ); return( out ); };


可以使用两次缩放对图像进行边缘检测。 代码见资源:http://download.csdn.net/detail/u010141025/7016239

    推荐阅读