opencvcanny源码解析

上传人:今*** 文档编号:105688968 上传时间:2019-10-13 格式:DOC 页数:10 大小:64.50KB
返回 下载 相关 举报
opencvcanny源码解析_第1页
第1页 / 共10页
opencvcanny源码解析_第2页
第2页 / 共10页
opencvcanny源码解析_第3页
第3页 / 共10页
opencvcanny源码解析_第4页
第4页 / 共10页
opencvcanny源码解析_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《opencvcanny源码解析》由会员分享,可在线阅读,更多相关《opencvcanny源码解析(10页珍藏版)》请在金锄头文库上搜索。

1、OpenCV Canny 源码解析 1986年,John F.Canny 完善了边缘检测理论,Canny算法以此命名。 Canny 算法的步骤: 1. 使用滤波器卷积降噪 2. 使用Sobel导数计算梯度幅值和方向 3. 非极大值抑制 + 滞后阈值 在正式处理前,用高斯滤平滑波器对图像做滤波降噪的操作,避免噪声点的干扰,但在OpenCV的canny源码中,没有进行高斯滤波,需要使用者自行滤波;有些资料将非极大值抑制和滞后阈值视为两个步骤也是可行的,但是在源码中非极大值抑制 和滞后阈值是同时进行的。canny源码的位置:opencvsourcesmodulesimgprocsrccanny.cp

2、p参考了网上许多资料,有不足之处请指正,谢谢。cpp view plain copy 在CODE上查看代码片派生到我的代码片/*M/ / / IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. / / By downloading, copying, installing or using the software you agree to this license. / If you do not agree to this license, do not download, install, / copy or

3、 use the software. / / / Intel License Agreement / For Open Source Computer Vision Library / / Copyright (C) 2000, Intel Corporation, all rights reserved. / Third party copyrights are property of their respective owners. / / Redistribution and use in source and binary forms, with or without modifica

4、tion, / are permitted provided that the following conditions are met: / / * Redistributions of source code must retain the above copyright notice, / this list of conditions and the following disclaimer. / / * Redistributions in binary form must reproduce the above copyright notice, / this list of co

5、nditions and the following disclaimer in the documentation / and/or other materials provided with the distribution. / / * The name of Intel Corporation may not be used to endorse or promote products / derived from this software without specific prior written permission. / / This software is provided

6、 by the copyright holders and contributors as is and / any express or implied warranties, including, but not limited to, the implied / warranties of merchantability and fitness for a particular purpose are disclaimed. / In no event shall the Intel Corporation or contributors be liable for any direct

7、, / indirect, incidental, special, exemplary, or consequential damages / (including, but not limited to, procurement of substitute goods or services; / loss of use, data, or profits; or business interruption) however caused / and on any theory of liability, whether in contract, strict liability, / o

8、r tort (including negligence or otherwise) arising in any way out of / the use of this software, even if advised of the possibility of such damage. / /M*/ #include precomp.hpp /* #if defined (HAVE_IPP) & (IPP_VERSION_MAJOR = 7) #define USE_IPP_CANNY 1 #else #undef USE_IPP_CANNY #endif */ #ifdef USE_

9、IPP_CANNY namespace cv static bool ippCanny(const Mat& _src, Mat& _dst, float low, float high) int size = 0, size1 = 0; IppiSize roi = _src.cols, _src.rows ; ippiFilterSobelNegVertGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size); ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &siz

10、e1); size = std:max(size, size1); ippiCannyGetSize(roi, &size1); size = std:max(size, size1); AutoBuffer buf(size + 64); uchar* buffer = alignPtr(uchar*)buf, 32); Mat _dx(_src.rows, _src.cols, CV_16S); if( ippiFilterSobelNegVertBorder_8u16s_C1R(_src.data, (int)_src.step, _dx.ptr(), (int)_dx.step, ro

11、i, ippMskSize3x3, ippBorderRepl, 0, buffer) 0 ) return false; Mat _dy(_src.rows, _src.cols, CV_16S); if( ippiFilterSobelHorizBorder_8u16s_C1R(_src.data, (int)_src.step, _dy.ptr(), (int)_dy.step, roi, ippMskSize3x3, ippBorderRepl, 0, buffer) 0 ) return false; if( ippiCanny_16s8u_C1R(_dx.ptr(), (int)_

12、dx.step, _dy.ptr(), (int)_dy.step, _dst.data, (int)_dst.step, roi, low, high, buffer) 0 ) return false; return true; #endif void cv:Canny( InputArray _src, OutputArray _dst, double low_thresh, double high_thresh, int aperture_size, bool L2gradient ) Mat src = _src.getMat(); /输入图像,必须为单通道灰度图 CV_Assert

13、( src.depth() = CV_8U ); / 8位无符号 _dst.create(src.size(), CV_8U); /根据src的大小构造目标矩阵dst Mat dst = _dst.getMat(); /输出图像,为单通道黑白图 / low_thresh 表示低阈值, high_thresh表示高阈值 / aperture_size 表示算子大小,默认为3 / L2gradient计算梯度幅值的标识,默认为false / 如果L2gradient为false 并且 apeture_size的值为-1(-1的二进制标识为:1111 1111) / L2gradient为false 则计算sobel导数时,用G = |Gx|+|Gy| / L2gradient为true 则计算sobel导数时,用G = Math.sqrt(Gx)2 + (Gy)2) 根号下 开平方 if (!L2gradient & (aperture_size & CV_CANNY_L2_GR

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号