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;
            }
        }

        m.CopyTo(mask);
    }
    maskHandle.Free();
}
时间: 2024-08-08 05:37:57

Study Emgu VoteForUniqueness的相关文章

Emgu学习之(二)——图像读取、显示、保存

visual Studio Community 2015 工程和源代码:http://pan.baidu.com/s/1o6u5Fdw 内容 在这篇文章中将提到以下内容: 从文件中读取图像 Image类 显示图像 保存图像 在上一篇文章Emgu学习之(一)——Emgu介绍中,我介绍了如何创建Emgu的工程,但是上一个Demo使用的是OpenCV的HighGUI窗体显示图像,这一 次我们要用WinForm窗体显示图像,并将图像进行操作后另存为新的图像文件.首先我们要做的是在Visual studi

[转载+原创]Emgu CV on C# (四) —— Emgu CV on 二值化

重点介绍了二值化原理及数学实现,并利用emgucv方法编程实现. 一.理论概述(转载,如果懂图像处理,可以略过,仅用作科普,或者写文章凑字数)  1.概述 图像二值化是图像处理中的一项基本技术,也是很多图像处理技术的预处理过程. 图像的预处理在进行图像二值化操作前要对图像进行预处理,包括彩色图像灰化和增强.由于选取阈值需要参照直方图,因此在图像进行处理后,我们再获取图像的直方图以帮助选取阈值.整个流程如下所示: 读取图像→灰度图像→图像增强→图像直方图→二值化处理 2.数学原理(转载,基本可以不

SHELL STUDY....tr的用法

一般我们使用tr来做字符串的替换,或者删除指定的字符串 tr的语法如下: tr [OPTION]... SET1 [SET2] -c, -C, --complement first complement SET1 将非SET1中的字符替换为SET2 [[email protected] ~]$ echo "lubinsu" | tr -c "l" "A" lAAAAAAA -d, --delete delete characters in SET

Oracle Study之--Oracle等待事件(1)

Oracle Study之--Oracle等待事件(1) 一. 等待事件的相关知识1.1 等待事件主要可以分为两类: 即空闲(IDLE)等待事件和非空闲(NON-IDLE)等待事件.1). 空闲等待事件指ORACLE正等待某种工作,在诊断和优化数据库的时候,不用过多注意这部分事件.2). 非空闲等待事件专门针对ORACLE的活动,指数据库任务或应用运行过程中发生的等待,这些等待事件 是在调整数据库的时候需要关注与研究的.在Oracle 10g中的等待事件有874个,11g中等待事件1118个.

MySQL Study之--MySQL下图形工具的使用(phpMyAdmin)

MySQL Study之--MySQL下图形工具的使用(phpMyAdmin) 系统环境: RedHat EL6 数据库:  MySQL 5.6.4-m7 phpMyAdmin是一个用PHP编写的软件工具,是以PHP为基础,以Web-Base方式架构在网站主机上的MySQL的数据库管理工具,让管理者可用Web接口管理MySQL数据库.借由此Web接口可以成为一个简易方式输入繁杂SQL语法的较佳途径,尤其要处理大量资料的汇入及汇出更为方便.其中一个更大的优势在于由于phpMyAdmin跟其他PHP

MySQL Study之--MySQL体系结构深入解析

MySQL Study之--MySQL体系结构深入解析 MySQL体系架构 由连接池组件.管理服务和工具组件.sql接口组件.查询分析器组件.优化器组件.缓冲组件.插件式存储引擎.物理文件组成.mysql是独有的插件式体系结构,各个存储引擎有自己的特点. MySQL内存结构: Mysql 进程结构 Mysql不像oracle那样是通过多进程来完成其功能的.默认情况下,InnoDB存储引擎的后台线程有7个: 4个IO thread, 1个master thread, 1个锁(lock)监控线程,

MySQl Study学习之--MySQl二进制日志管理

MySQl Study学习之--MySQl二进制日志管理 MySQL二进制日志(Binary Log):   a.它包含的内容及作用如下:    包含了所有更新了数据或者已经潜在更新了数据(比如没有匹配任何行的一个DELETE)    包含关于每个更新数据库(DML)的语句的执行时间信息    不包含没有修改任何数据的语句,如果需要启用该选项,需要开启通用日志功能    主要目的是尽可能的将数据库恢复到数据库故障点,因为二进制日志包含备份后进行的所有更新    用于在主复制服务器上记录所有将发送

Emgu学习笔记(一)安装及运行Sample

1.简单说明 Emgu是Dot Net平台对OpenCV的封装,本质上没有增加新功能,是通过Dot Net的平台调用技术直接调用OpenCV C++语言写的库,使用我们可以方便用.net平台通过OpenCV去处理图像,最大的好处是可以利用.net丰富的类库及各种资源,还有.net的开发效率较快,让不熟悉C++语言的人也可以很方便使用OpenCV. Emgu的官网是 http://www.emgu.com ,根据官网说法,Emgu是跨平台的,可以在Winodws.Linux.Mac OS X.IP

Study ExtJS 4.x

Before we start: 1.  All my knowledge comes from Internet and I will try my best to present the reference link. 2.  I would be glad if u could join me with the same topic. 3.  I am green hand, really.. 4.  never code for u , u code for urself.(I give