(a1,a2,...an),B=(b1,b2,...,bn)，则AB间的距离为：
d(A,B)=[∑(ai−bi)2]−−−−−−−−−−−√(i=1,2,...,n)d(A,B)=[∑(ai−bi)2](i=1,2,...,n)

double euclidean_distance(Mat baseImg, Mat targetImg) { double sumDescriptor =
0; for (int i = 0; i < baseImg.cols; i++) { double numBase = abs(baseImg.at<
float>(0, i)); double numTarget = abs(targetImg.at<float>(0, i)); sumDescriptor
+=pow(numBase-numTarget, 2); } double simility = sqrt(sumDescriptor); return
simility; }

Distance也能用来计算两个向量的相似度；即通过比较向量每一位是否相同，若不同则汉明距离加1，这样得到汉明距离。向量相似度越高，对应的汉明距离越小。如10001001和10110001有3位不同。

，其余弦值为：
cosθ=∑n1(ai×bi)∑n1a2i√×∑n1b2i√cosθ=∑1n(ai×bi)∑1nai2×∑1nbi2
double cos_distance(Mat baseImg, Mat targetImg) { double squSumB = 0; double
squSumT =0; double innerPro = 0; for (int i = 0; i < baseImg.cols; i++) { double
numBase =abs(baseImg.at<float>(0, i)); double numTarget = abs(targetImg.at<
float>(0, i)); squSumB = squSumB + numBase*numBase; squSumT = squSumT +
numTarget*numTarget; innerPro = innerPro + numBase*numTarget; }double modB =
sqrt(squSumB); double modT = sqrt(squSumT); double simility = innerPro /
(modB*modT);return simility; }