Merge pull request #6792 from paroj:jaccard_distance
This commit is contained in:
commit
c8693f01a3
@ -51,6 +51,7 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
#include "opencv2/core/cvdef.h"
|
#include "opencv2/core/cvdef.h"
|
||||||
#include "opencv2/core/cvstd.hpp"
|
#include "opencv2/core/cvstd.hpp"
|
||||||
@ -1844,7 +1845,26 @@ Rect_<_Tp> operator | (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
|
|||||||
return c |= 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 //////////////////////////////
|
////////////////////////////// RotatedRect //////////////////////////////
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user