两个向量之间的OpenCV欧几里德距离

时间:2014-04-16 09:48:43

标签: opencv vector matrix euclidean-distance

我想计算两个向量之间的欧氏距离(或两个Matrx行,并不重要)。在OpenCV中是否有一个很好的功能?

3 个答案:

答案 0 :(得分:22)

yes.

Mat a,b; // num of rows/cols/channels does not matter, they just have to be equal for both

double dist = norm(a,b,NORM_L2);

答案 1 :(得分:2)

来源:OpenCV, C++: Distance between two points

Mat pts1(nPts, 1, CV_8UC2), pts2(nPts, 1, CV_8UC2);
// populate them
Mat diffPts = pts1-pts2;
Mat ptsx, ptsy;
// split your points in x and y vectors. maybe separate them from start
Mat dist;
magnitude(ptsx, ptsy, dist); // voila!

答案 2 :(得分:0)

与python相同:

    dist = cv2.norm(pts - dst, cv2.NORM_L2)