首先对图像进行缩放:
用到的函数: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
推荐阅读
- 人脸识别|【人脸识别系列】| 实现自动化妆
- OpenCV|OpenCV-Python实战(18)——深度学习简介与入门示例
- opencv|图像处理之椒盐噪声的添加与去除
- 人脸识别|【人脸识别系列】| 实现人脸截图保存并编写128维特征向量
- opencv|网络爬虫入门练习
- OpenCV|【OpenCV 完整例程】89. 带阻滤波器的传递函数
- OpenCV|【OpenCV 完整例程】90. 频率域陷波滤波器
- OpenCV|【OpenCV 完整例程】22. 图像添加非中文文字
- OpenCV|【OpenCV 完整例程】91. 高斯噪声、瑞利噪声、爱尔兰噪声
- opencv|python+opencv车道线,实线虚线的检测