两个向量之间的相似度计算常用方法

        在实际应用中,用传统方法计算完特征descriptors之后需要对两个特征之间的相似度进行判别,这就涉及到向量相似度的比较。关于向量相似度的计算,现有的几种基本方法都是基于向量的,其实也就是计算两个向量之间的距离,距离越大相似度越大。

 

 

参考编程案例:

bool ComputeDecsDistance(vector descriptors1, vector descriptors2, float & t_value) {
	float dp1mean, dp2mean, sum1dp = 0, sum2dp = 0;
	for (int i = 0; i < descriptors1.size(); i++) {
		sum1dp += descriptors1[i];
		sum2dp += descriptors2[i];
	}
	dp1mean = sum1dp / descriptors1.size();
	dp2mean = sum2dp / descriptors2.size();
	float value = 0, dp1square = 0, dp2square = 0;
	for (int i = 0; i < descriptors1.size(); i++) {
		float sub_des1 = descriptors1[i] - dp1mean;
		float sub_des2 = descriptors2[i] - dp2mean;
		value += (sub_des1) * (sub_des2);
		dp1square += sub_des1 * sub_des1;
		dp2square += sub_des2 * sub_des2;
	}
	t_value = value / (sqrt(dp1square*dp2square) + 1e-6);
	return true;
}

参考文章:

【1】https://wenku.baidu.com/view/3da98708876fb84ae45c3b3567ec102de2bddfaa.html

你可能感兴趣的:(General,Algorithm)