OpenCV密集特征检测器

时间:2015-06-04 14:54:37

标签: c++ opencv descriptor

我正在使用openCV进行一些密集的特征提取。例如,代码

DenseFeatureDetector detector(12.f, 1, 0.1f, 10);

我不太了解上述构造函数中的参数。这是什么意思 ?阅读opencv documentation也无济于事。在文档中,参数是:

DenseFeatureDetector( float initFeatureScale=1.f, int featureScaleLevels=1,
                          float featureScaleMul=0.1f,
                          int initXyStep=6, int initImgBound=0,
                          bool varyXyStepWithScale=true,
                          bool varyImgBoundWithScale=false );

他们应该做什么?也就是scale,initFeatureScale,featureScaleLevels等是什么意思?你怎么知道密集采样的网格或网格间距等。

2 个答案:

答案 0 :(得分:0)

我正在使用带有密集检测器的opencv,我想我可以帮助你。我不确定我会说些什么,但经验告诉我。

当我使用密集探测器时,我会在那里传递灰度图像。检测器制作一些阈值滤波器,其中opencv使用灰度最小值,用于变换图像。灰度级比阈值更高的像素将像黑点一样,其他的是白点。这个动作在一个循环中重复,其中阈值将越来越大。因此,参数initFeatureScale确定用于执行此循环的第一个阈值,featureScaleLevels参数指示在一个循环迭代与下一个循环迭代之间该阈值的大小,而featureScaleMul是计算下一个阈值的乘法因子。

无论如何,如果您正在寻找一个最佳参数来使用密集检测器来检测任何特定点您将提供我为此制作的程序。它在github中被解放了。这是一个程序,你可以测试一些探测器(密集探测器就是其中之一)并检查它是如何工作的,如果你改变它们的参数,这要归功于用户界面,只要你执行程序就可以改变探测器参数。您将看到检测到的点将如何变化。要试一试,只需点击link,然后下载文件即可。您可能需要几乎所有文件来执行该程序。

答案 1 :(得分:0)

提前道歉,我主要使用Python,所以我不会通过引用C ++来压抑自己。

DenseFeatureDetector使用KeyPoints填充矢量以传递给计算特征描述符。这些关键点具有点向量及其比例集。在文档中,scale是关键点的像素半径。

KeyPoints在传递给DenseFeatureVector的图像矩阵的宽度和高度上均匀分布。

现在参数:

<强> initFeatureScale 设置初始KeyPoint特征半径(以我所知,这没有效果)

<强> featureScaleLevels     我们希望制作关键点的比例数

<强> featureScaleMuliplier     通过featureScaleLevels对initFeatureScale进行比例调整,此比例调整也可应用于边框(initImgBound)和步长(initxystep)。因此,当我们设置featureScaleLevels&gt; 1时,此乘数将应用于连续的比例,以调整特征比例,步长和图像周围的边界。

<强> initXyStep     以像素为单位移动列和行。我希望自我解释。

<强> initImgBound     要在图像周围忽略的行/列边界区域(像素),因此,初始化为10的100x100图像将在图像的中心80x80部分创建关键点。

<强> varyXyStepWithScale     布尔值,如果我们有多个featureScaleLevels,我们想使用featureScaleMultiplier调整步长。

<强> varyImgBoundWithScale     布尔值,作为varyXyStepWithScale,但应用于边框。

这是OpenCV 2.4.3源代码中的sensors.cpp的DenseFeatureDetector源代码,它可能比我的解释更好:

DenseFeatureDetector::DenseFeatureDetector( float _initFeatureScale, int _featureScaleLevels,
                                      float _featureScaleMul, int _initXyStep,
                                      int _initImgBound, bool _varyXyStepWithScale,
                                      bool _varyImgBoundWithScale ) :
    initFeatureScale(_initFeatureScale), featureScaleLevels(_featureScaleLevels),
    featureScaleMul(_featureScaleMul), initXyStep(_initXyStep), initImgBound(_initImgBound),
    varyXyStepWithScale(_varyXyStepWithScale), varyImgBoundWithScale(_varyImgBoundWithScale)
{}


void DenseFeatureDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask ) const
{
    float curScale = static_cast<float>(initFeatureScale);
    int curStep = initXyStep;
    int curBound = initImgBound;
    for( int curLevel = 0; curLevel < featureScaleLevels; curLevel++ )
    {
        for( int x = curBound; x < image.cols - curBound; x += curStep )
        {
            for( int y = curBound; y < image.rows - curBound; y += curStep )
            {
                keypoints.push_back( KeyPoint(static_cast<float>(x), static_cast<float>(y), curScale) );
            }
        }

        curScale = static_cast<float>(curScale * featureScaleMul);
        if( varyXyStepWithScale ) curStep = static_cast<int>( curStep * featureScaleMul + 0.5f );
        if( varyImgBoundWithScale ) curBound = static_cast<int>( curBound * featureScaleMul + 0.5f );
    }

    KeyPointsFilter::runByPixelsMask( keypoints, mask );
}

根据DenseFeatureDetector生成的KeyPoints,您可能期望计算调用将使用相关关键点检测算法(例如角度)计算其他KeyPoint特征。不幸的是,在Python下,SIFT的情况并非如此 - 我没有看过其他的特征检测器,也没有看过C ++中的行为。

另请注意,DenseFeatureDetector不在OpenCV 3.2中(不确定它在哪个版本中被删除)。