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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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);
回答2:
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!