opencv实现图像缩放及canny边缘处理

// ZoomCanny.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include "highgui.h"
#include "cv.h"


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);
return (out);
}


IplImage* doCanny(
IplImage* in,
double lowThresh,
double highThresh,
int aperture
)
{
if (in->nChannels != 1) {
return 0;
}
IplImage* out = cvCreateImage(
cvSize(in->width, in->height),
IPL_DEPTH_8U,
1);
cvCanny(in, out, lowThresh, highThresh, aperture);
return (out);
}


int main(int argc, char* argv[])
{
IplImage* in = cvLoadImage("uie7po3o1372.jpg", 0);
IplImage* img1 = doPyrDown(in, IPL_GAUSSIAN_5x5);
IplImage* img2 = doPyrDown(img1, IPL_GAUSSIAN_5x5);
IplImage* img3 = doCanny(in, 10, 100, 3);
doCanny(in, 1, 2.4, 3);


cvNamedWindow("Example0", CV_WINDOW_AUTOSIZE);
cvShowImage("Example0", in);


cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
cvShowImage("Example1", img1);


cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
cvShowImage("Example2", img2);


cvNamedWindow("Example3", CV_WINDOW_AUTOSIZE);
cvShowImage("Example3", img3);


cvWaitKey(0);


cvReleaseImage(&in);
cvReleaseImage(&img1);
cvReleaseImage(&img2);
cvReleaseImage(&img3);
cvDestroyWindow("Example0");
cvDestroyWindow("Example1");
cvDestroyWindow("Example2");
cvDestroyWindow("Example3");

return 0;

}

从左至右分别为:原图,缩放1/2,缩放1/4,canny边缘检测。


opencv实现图像缩放及canny边缘处理_第1张图片

你可能感兴趣的:(filter)