Giou简洁算法[通俗易懂]

Giou简洁算法[通俗易懂]defGiou(rect_a,rect_b):ax0,ay0,ax1,ay1=rect_a#a框坐标bx0,by0,bx1,by1=rect_b#b框坐标#外框就是包含a与b的最小矩形outx0=min(ax0,bx0)#外框x0outx1=max(ax1,bx1)#外框x1outy0=min(ay0,by0)#外框y0outy1=m...
def Giou(rect_a, rect_b):  
    ax0, ay0, ax1, ay1 = rect_a   #a框坐标
    bx0, by0, bx1, by1 = rect_b   #b框坐标

#外框就是包含a与b的最小矩形
    outx0 = min(ax0, bx0)        #外框x0
    outx1 = max(ax1, bx1)        #外框x1
    outy0 = min(ay0, by0)        #外框y0
    outy1 = max(ay1, by1)        #外框y1

    aw = ax1 - ax0        #a框宽
    ah = ay1 - ay0
    bw = bx1 - bx0
    bh = by1 - by0



    out_w = (outx1 - outx0)       #外框宽
    out_h = (outy1 - outy0)

    a_s = aw * ah                  #a面积
    b_s = bw * bh

    inter_w = max(aw + bw - out_w, 0)        #a、b重叠框宽

    inter_h = max(ah + bh - out_h, 0)

    inter_s = inter_w * inter_h        #a、b重叠框面积

    out_s = out_w * out_h

    u = a_s +b_s - inter_s              #a并b面积

    ##    print("交集",inter_s)
    ##    print("并集",u)
    ##    print("补cc:",out_s-u)
    ##    print("外框面积:",out_s)

    giou = inter_s / u - (out_s - u) / out_s

    return giou
只听到从架构师办公室传来架构君的声音:
泻水置平地,各自东西南北流。有谁来对上联或下联?
架构君码字不易,如需转载,请注明出处:https://javajgs.com/archives/148363
0
   

发表评论