opencv: 角点检测源码分析;
Posted yinwei-space
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv: 角点检测源码分析;相关的知识,希望对你有一定的参考价值。
以下6个函数是opencv有关角点检测的函数 ConerHarris, cornoerMinEigenVal,CornorEigenValsAndVecs, preConerDetect, conerSubPix, goodFeaturesToTracks, 其中, 前三个都调用静态函数cornerEigenValsVecs
1、静态函数cornerEigenValsVecs;
static void cornerEigenValsVecs( const Mat& src, Mat& eigenv, int block_size, int aperture_size, int op_type, double k=0., int borderType=BORDER_DEFAULT ) { #ifdef HAVE_TEGRA_OPTIMIZATION if (tegra::useTegra() && tegra::cornerEigenValsVecs(src, eigenv, block_size, aperture_size, op_type, k, borderType)) return; #endif #if CV_TRY_AVX bool haveAvx = CV_CPU_HAS_SUPPORT_AVX; #endif #if CV_SIMD128 bool haveSimd = hasSIMD128(); #endif int depth = src.depth(); double scale = (double)(1 << ((aperture_size > 0 ? aperture_size : 3) - 1)) * block_size; if( aperture_size < 0 ) scale *= 2.0; if( depth == CV_8U ) scale *= 255.0; scale = 1.0/scale; CV_Assert( src.type() == CV_8UC1 || src.type() == CV_32FC1 ); Mat Dx, Dy; if( aperture_size > 0 ) { Sobel( src, Dx, CV_32F, 1, 0, aperture_size, scale, 0, borderType ); Sobel( src, Dy, CV_32F, 0, 1, aperture_size, scale, 0, borderType ); } else { Scharr( src, Dx, CV_32F, 1, 0, scale, 0, borderType ); Scharr( src, Dy, CV_32F, 0, 1, scale, 0, borderType ); } Size size = src.size(); Mat cov( size, CV_32FC3 ); int i, j; for( i = 0; i < size.height; i++ ) { float* cov_data = cov.ptr<float>(i); const float* dxdata = Dx.ptr<float>(i); const float* dydata = Dy.ptr<float>(i); #if CV_TRY_AVX if( haveAvx ) j = cornerEigenValsVecsLine_AVX(dxdata, dydata, cov_data, size.width); else #endif // CV_TRY_AVX j = 0; #if CV_SIMD128 if( haveSimd ) { for( ; j <= size.width - v_float32x4::nlanes; j += v_float32x4::nlanes ) { v_float32x4 v_dx = v_load(dxdata + j); v_float32x4 v_dy = v_load(dydata + j); v_float32x4 v_dst0, v_dst1, v_dst2; v_dst0 = v_dx * v_dx; v_dst1 = v_dx * v_dy; v_dst2 = v_dy * v_dy; v_store_interleave(cov_data + j * 3, v_dst0, v_dst1, v_dst2); } } #endif // CV_SIMD128 for( ; j < size.width; j++ ) { float dx = dxdata[j]; float dy = dydata[j]; cov_data[j*3] = dx*dx; cov_data[j*3+1] = dx*dy; cov_data[j*3+2] = dy*dy; } } //盒式均值滤波; boxFilter(cov, cov, cov.depth(), Size(block_size, block_size), Point(-1,-1), false, borderType ); if( op_type == MINEIGENVAL ) calcMinEigenVal( cov, eigenv ); //最小特征值; 如果最小的特征值都满足角点的要求,那么说明是角点,并且是强角点; else if( op_type == HARRIS ) calcHarris( cov, eigenv, k ); else if( op_type == EIGENVALSVECS ) calcEigenValsVecs( cov, eigenv ); }
2、preConerDetect函数分析;
3、cornorSubPix函数分析;
4、goodFeaturesToTrack函数分析;
注: 该博文为扩展型;
以上是关于opencv: 角点检测源码分析;的主要内容,如果未能解决你的问题,请参考以下文章