Close

Detection boxes coalescing solution

A project log for Crop Orientated Agricultural Navigation System

Navigate an agri-robot using the crops themselves as the guide via computer vision.

Tegwyn☠TwmffatTegwyn☠Twmffat 06/09/2019 at 17:100 Comments

BEFORE:


AFTER:

detectNet.cpp line 446:
BEFORE:

inline static bool rectOverlap(const float6& r1, const float6& r2)
{
    return ! ( r2.x > r1.z  
        || r2.z < r1.x
        || r2.y > r1.w
        || r2.w < r1.y
        );
} 

AFTER

inline static bool rectOverlap(const float6& r1, const float6& r2)
{
    // The rectangles do not overlap at all
    if ( r2.x > r1.z ||          r2.z < r1.x ||
         r2.y > r1.w ||
         r2.w < r1.y ) return false;

    else     {
        float overlap_x = std::min(r2.z,r1.z) - std::max(r2.x,r1.x);
        float overlap_y = std::min(r2.w,r1.w) - std::max(r2.y,r1.y);
        float area_overlap = overlap_x * overlap_y;
        
        float area_r1 = (r1.z-r1.x) * (r1.w-r1.y);
        float area_r2 = (r2.z-r2.x) * (r2.w-r2.y);
        
        // The rectangles overlap by less than 75% of either's area
        if ((area_overlap < 0.25*area_r1) &&             (area_overlap < 0.25*area_r2)) return false;
        
        // The rectangels overlap
        return true;
    }
}

Discussions