在KNN计算的图像中绘制匹配对,以及Features2DToolbox.DrawMatches中的潜在错误

far*_*rsa 7 c# opencv emgucv

我写了一个代码,它通过KNN算法找到K最接近的匹配.在获取matMatch和matchIndices之后,我尝试在两个结果帧之间绘制匹配对.

我将matMaskmatchIndices提供给函数Features2DToolbox.DrawMatches:

Image<Bgr, byte> imResult = Features2DToolbox.DrawMatches(imModelCurr, imModel.keyPoints, imObserPrev,imObser.keyPoints, **matchIndices**, new Bgr(System.Drawing.Color.Yellow), new Bgr(System.Drawing.Color.Red), **matMask**, Features2DToolbox.KeypointDrawType.NOT_DRAW_SINGLE_POINTS);
Run Code Online (Sandbox Code Playgroud)

http://www.emgu.com/wiki/files/2.4.0/document/html/e92d37e6-fe4a-ad09-9304-cd2d2533bfa8.htm但我注意到它让我在匹配对之间错误绘制了图:

在此输入图像描述

然后我试着自己实现这样的功能:

 for (int i = 0; i < matMask.Rows; ++i)
        {
            if (**matMask[i, 0]** > 0) 
            {
                int indForCurrFrm = **matchIndices[i, 0]**;
                int indForPrevFrm = i;

                //for frame i-1
                PointF fromFirstFrame = getImgObserved(keyPoints[indForPrevFrm]);

                //for frame i
                PointF NextCorrespondingMatchedFrame = getImModelXY(keyPoints[indForCurrFrm]);

                imColorPrv2.Draw(new CircleF(fromFirstFrame, 5), new Bgr(mtchColor), 3);// for frame i-1
                imColorShow.Draw(new CircleF(NextCorrespondingMatchedFrame, 5), new Bgr(mtchColor), 3); // for frame i

                 // draw line on my own matching
              imResult.Draw(new LineSegment2DF(fromFirstFrame,NextCorrespondingMatchedFrame),new Bgr(System.Drawing.Color.FloralWhite),1);

            }
        }
Run Code Online (Sandbox Code Playgroud)

并获取相应的对点坐标(X,Y)并自己绘制[见快照结果].

一个左下角你可以看到匹配(用白线表示)和每个对应的对用一个相同颜色的圆[由我自己的功能],在另一个侧面 - 右下角,它是由Emgu的DrawMatches函数绘制的结果请注意这两个函数使用相同的matMash和matchIndices.

所以我想知道EMGU的DrawMatches是否有错误或我做错了什么?

Y.A*_*.AL 0

使用每个相应对的描述符之间的欧几里德距离从matchIndices中过滤最佳匹配可能非常有用。有时,第一张图像中的一个关键点可以很好地匹配第二张图像中的许多关键点,这可能会混淆结果中的绘制线。

过滤可能是这样的:

vector< DMatch > filtered_matches;

 for( int i = 0; i < descriptors_of_model.rows; i++ )
    { 
      if( matchIndices[i].distance < SMALL_THRESHOLD )
          filtered_matches.push_back( matchIndices[i]); 

     }
Run Code Online (Sandbox Code Playgroud)