zoukankan      html  css  js  c++  java
  • Study Emgu VoteForUniqueness

    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;  //if the distance is too similiar, then elimilate the feature by set mask to 0
                }
            }
    
            m.CopyTo(mask);
        }
        maskHandle.Free();
    }
  • 相关阅读:
    antd表单不显示label和冒号
    create-react-app 区分环境 环境变量
    在actionCreator中使用getState,数据格式是immutable
    给树状数据添加层级id
    vscode中的正则搜索与替换演示,删除对象中不要的属性及属性值
    http-proxy-middleware做代理时,自定义复杂的匹配规则
    antd省市区级联
    axios封装
    jmeter-07-参数化-关联(json提取)
    jmeter-06-参数化-csv参数化
  • 原文地址:https://www.cnblogs.com/shengguang/p/5176501.html
Copyright © 2011-2022 走看看