What does the distance attribute in DMatches mean?

In this context, a feature is a point of interest on the image. In order to compare features, you "describe" them using a feature detector. Each
feature is then associated to a descriptor. When you match features, you actually match their descriptors.

A descriptor is a multidimensional vector. It can be real-valued (e.g. SIFT)
or binary (e.g. BRIEF).

A matching is a pair of descriptors, one from each image, which are the most similar among all of the descriptors. And of course, to find the descriptor in image B that is the most similar to a descriptor in image A, you need a measure of this similarity.

There are multiple ways to compute a "score of similarity" between two vectors. For real-valued descriptors, the Euclidean
distance
 is often used, when the Hamming
distance
 is common for binary descriptors.

As a conclusion, we can now understand the distance attribute:
it is the score of similarity between the two descriptors of a match.

Usually when you are matching two features, you are actually comparing two vectors under certain distance metrics. Now let‘s assume your feature is SIFT with 128 dimensions, and you compare two SIFT features a and b using
Euclidean distance, then DMatch.distance is
equal to

int main()
{
	Mat img_1 = imread("111.jpg");
	Mat img_2 = imread("112.jpg");
	if (!img_1.data || !img_2.data)
	{
		cout << "error reading images " << endl;
		return -1;
	}    

	ORB orb;
	vector<KeyPoint> keyPoints_1, keyPoints_2;
	Mat descriptors_1, descriptors_2;    

	orb(img_1, Mat(), keyPoints_1, descriptors_1);
	orb(img_2, Mat(), keyPoints_2, descriptors_2);    

	BFMatcher matcher(NORM_L2);
	vector<DMatch> matches;
	matcher.match( descriptors_1, descriptors_2, matches );

	double max_dist = 0; double min_dist = 100;
	//-- Quick calculation of max and min distances between keypoints
	for( int i = 0; i < descriptors_1.rows; i++ )
	{
		double dist = matches[i].distance;
		if( dist < min_dist ) min_dist = dist;
		if( dist > max_dist ) max_dist = dist;
	}
	printf("-- Max dist : %f \n", max_dist );
	printf("-- Min dist : %f \n", min_dist );
	//-- Draw only "good" matches (i.e. whose distance is less than 0.6*max_dist )
	//-- PS.- radiusMatch can also be used here.
	std::vector< DMatch > good_matches;
	for( int i = 0; i < descriptors_1.rows; i++ )
	{
		if( matches[i].distance < 0.5*max_dist )
		{
			good_matches.push_back( matches[i]);
		}
	}    

	Mat img_matches;
	drawMatches(img_1, keyPoints_1, img_2, keyPoints_2,
		good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
		vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
	imshow( "Match", img_matches);
	cvWaitKey();
	return 0;
}  
时间: 2024-10-10 15:20:08

What does the distance attribute in DMatches mean?的相关文章

ArcGIS API For Android Errors汇总

API客户端异常错误的发生通常是由于不正确的方法参数,对象状态依赖,或网络条件. //*******推荐使用方法,按下Ctrl+F搜索错误代码,再查看与代码对应的解释.********// ArcGIS弹出错误 11000 Invalid attributes or geometry on the associated GeoElement. 11001 Null value is not allowed. 11002 Value is out of range. 11003 Value exc

Unity3d Attribute 总结(转)

举两个例子,在变量上使用[SerializeFiled]属性,可以强制让变量进行序列化,可以在Unity的Editor上进行赋值.在Class上使用[RequireComponent]属性,就会在Class的GameObject上自动追加所需的Component. 以下是Unity官网文档中找到的所有Attribute,下面将按照顺序,逐个对这些Attribute进行说明和小的测试.部分例子使用了Unity官方的示例. UnityEngine AddComponentMenu 可以在UnityE

461.求两个数字转成二进制后的“汉明距离” Hamming Distance

public class Solution { public int HammingDistance(int x, int y) { int distance = 0; string sX = Convert.ToString(x, 2); string sY = Convert.ToString(y, 2); int maxLength = Math.Max(sX.Length, sY.Length); //填充0,使两个字符串右对齐 sX = sX.PadLeft(maxLength, '0

AttributeError: &#39;module&#39; object has no attribute &#39;dumps&#39;

报错: [[email protected] ~]# ./json.py DATA: [{'a': 'A', 'c': 3.0, 'b': (2, 4)}] Traceback (most recent call last): File "./json.py", line 4, in <module> import json File "/root/json.py", line 8, in <module> data_string = jso

LeetCode 72 Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word: a) Insert a character b) Delete a character c) Repla

Django admin 中抛出 &#39;WSGIRequest&#39; object has no attribute &#39;user&#39;的错误

这是Django版本的问题,1.9之前,中间件的key为MIDDLEWARE_CLASSES, 1.9之后,为MIDDLEWARE.所以在开发环境和其他环境的版本不一致时,要特别小心,会有坑. 将settings里的MIDDLEWARE_CLASSES默认配置顺序改成如下 MIDDLEWARE_CLASSES = [ 'django.middleware.security.SecurityMiddleware', 'django.middleware.common.CommonMiddlewar

JavaScript中的property和attribute的区别

时间: 2013-09-06 | 10:24 作者: 玉面小飞鱼 分类: DOM, js相关, 前端技术 2,222 次浏览 1. 定义 Property:属性,所有的HTML元素都由HTMLElement类型表示,HTMLElement类型直接继承自Element并添加了一些属性,添加的这些属性分别对应于每个HTML元素都有下面的这5个标准特性: id,title,lang,dir,className.DOM节点是一个对象,因此,他可以和其他的JavaScript对象一样添加自定义的属性以及方

module has no attribute &#39;seq2seq&#39;

tensorflow 中tf.nn.seq2seq.sequence_loss_by_example to tf.contrib.legacy_seq2seq.sequence_loss_by_example tf.nn.rnn_cell. to tf.contrib.rnn. 1.0修改了很多地方,错误可取官网搜索. module has no attribute 'seq2seq'

CVS导出&amp;&amp;自定义Attribute的使用

1.cvs导出:List转为byte[] /// <summary> /// CvsExport帮助类 /// </summary> public static class CvsExportHelper { /// <summary> /// Creates the CSV from a generic list. /// </summary>; /// <typeparam name="T"></typeparam&