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();
    }
  • 相关阅读:
    用NHibernate创建数据库时出现的问题
    Conceptual Overview (.NET 5概念描述)
    网页前端开发,对于图片慢加载简介
    opencv实现人脸识别(五) 运用tkinter进行GUI绘制 整合人脸识别模块
    opencv实现人脸识别(四) 人脸识别模块
    opencv实现人脸识别(三) 训练图片模块
    opencv实现人脸识别(二) 人脸图像采集模块
    opencv实现人脸识别(一)opencv的相关知识了解
    python实现文件搜索工具(简易版)
    expect实现非交互
  • 原文地址:https://www.cnblogs.com/shengguang/p/5176501.html
Copyright © 2011-2022 走看看