IOU for two ellipses overlap in OpenCV C++

Viewed 658

I was looking for some C++ built-in or implemented functions for calculating two ellipses overlap according to IOU (Intersection Over Union) a.k.a. Jaccard's Coefficient and I got to find it implemented, apparently, in the new version of OpenCV under this file

static inline float rotatedRectIOU(const RotatedRect& a, const RotatedRect& b)
{
    std::vector<Point2f> inter;
    int res = rotatedRectangleIntersection(a, b, inter);
    if (inter.empty() || res == INTERSECT_NONE)
        return 0.0f;
    if (res == INTERSECT_FULL)
        return 1.0f;
    float interArea = contourArea(inter);
    return interArea / (a.size.area() + b.size.area() - interArea);
}

And because I am using older OpenCV version I tried only to copy the code as it seems not to be dependent on any other resources. The code runs very smoothly. However, the result is astonishingly wrong I am not sure why.

enter image description here

0 Answers
Related