I want to calculate the euclidean distance between two vectors (or two Matrx rows, doesn't matter). Is there a good function for that in OpenCV?
Asked
Active
Viewed 2.4k times
3 Answers
1
Source: 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!
-
-
@Sherzod. This answer was a long time ago that I do not remember exactly. However, what I can see from the code is, after you compute diffPts, you can extract the x part into ptsx and the y part into ptsy. Finally, you can use the magnitude function – rafaoc May 23 '20 at 15:17