提交 c8693f01 编写于 作者: A Alexander Alekhin

Merge pull request #6792 from paroj:jaccard_distance

......@@ -51,6 +51,7 @@
#include <climits>
#include <cfloat>
#include <vector>
#include <limits>
#include "opencv2/core/cvdef.h"
#include "opencv2/core/cvstd.hpp"
......@@ -1844,7 +1845,26 @@ Rect_<_Tp> operator | (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
return c |= b;
}
/**
* @brief measure dissimilarity between two sample sets
*
* computes the complement of the Jaccard Index as described in <https://en.wikipedia.org/wiki/Jaccard_index>.
* For rectangles this reduces to computing the intersection over the union.
*/
template<typename _Tp> static inline
double jaccardDistance(const Rect_<_Tp>& a, const Rect_<_Tp>& b) {
_Tp Aa = a.area();
_Tp Ab = b.area();
if ((Aa + Ab) <= std::numeric_limits<_Tp>::epsilon()) {
// jaccard_index = 1 -> distance = 0
return 0.0;
}
double Aab = (a & b).area();
// distance = 1 - jaccard_index
return 1.0 - Aab / (Aa + Ab - Aab);
}
////////////////////////////// RotatedRect //////////////////////////////
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册