码迷,mamicode.com
首页 > 其他好文 > 详细

Study Emgu VoteForUniqueness

时间:2016-02-01 23:51:55      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:

Recently i was studying Emgu, but find there is a bug in the VoteForUniqueness function in class Features2DToolbox.

The idea of "VoteForUniqueness" is to filter ambiguous matchings. Lets say you want to match the points of image A with the points of image B.

Here is how it works :

  • "KnnMatch" is looking for 2-Nearest Neighbor for each point of image A in image B.
  • In image B, if the 1st and 2nd neighbors are too similar (the distance ratio is less than 0.8), we consider that we don‘t know which one is the best matching, so the matching is filtered (deleted).

Be awarded that here, when we speak about nearest neighbor and distance, we talk about the distance between the features of points (not the position).

According to the functionality of VoteForUniqueness, we need to fix a bug inside the function. 

When the n ratio of earest and the 2nd nearest is larger than the threshold, which means they are two similar, we need to remove that match by mask them out.

/// <summary>
/// Filter the matched Features, such that if a match is not unique, it is rejected.
/// </summary>
/// <param name="uniquenessThreshold">The distance different ratio which a match is consider unique, a good number will be 0.8</param>
/// <param name="mask">This is both input and output. This matrix indicates which row is valid for the matches.</param>
/// <param name="matches">Matches. Each matches[i] is k or less matches for the same query descriptor.</param> 
public static void VoteForUniqueness(VectorOfVectorOfDMatch matches, double uniquenessThreshold, Mat mask)
{
    MDMatch[][] mArr = matches.ToArrayOfArray();
    byte[] maskData = new byte[mArr.Length];
    GCHandle maskHandle = GCHandle.Alloc(maskData, GCHandleType.Pinned);
    using (Mat m = new Mat(mArr.Length, 1, DepthType.Cv8U, 1, maskHandle.AddrOfPinnedObject(), 1))
    {
        mask.CopyTo(m);
        for (int i = 0; i < mArr.Length; i++)
        {
            //Origianlly is mArr[i][0].Distance / mArr[i][1].Distance) < uniquenessThreshold
            if (maskData[i] != 0 && (mArr[i][0].Distance / mArr[i][1].Distance) >= uniquenessThreshold)
            {
                maskData[i] = (byte)0;
            }
        }

        m.CopyTo(mask);
    }
    maskHandle.Free();
}

 

Study Emgu VoteForUniqueness

标签:

原文地址:http://www.cnblogs.com/shengguang/p/5176501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!