简体   繁体   中英

Calculate intersection over union of two predictions

I need to calculate the intersection over union of two predictions that for example dont intersect. My code is the folllowing:

    yminA = max(coordenadas_A[0]*1024,coordenadas_B[0]*1024)
    xminA = max(coordenadas_A[1]*1024,coordenadas_B[1]*1024)
    ymaxA = max(coordenadas_A[2]*1024,coordenadas_B[2]*1024)
    xmaxA = max(coordenadas_A[3]*1024,coordenadas_B[3]*1024)

    interArea = max(0, ymaxA - yminA + 1) * max(0, xmaxA - xminA + 1)

    boxAArea = (coordenadas_A[2]*1024 - coordenadas_A[0]*1024 + 1) * (coordenadas_A[3]*1024 - coordenadas_A[1]*1024 + 1)
    boxBArea = (coordenadas_B[2]*1024 - coordenadas_B[0]*1024 + 1) * (coordenadas_B[3]*1024 - coordenadas_B[1]*1024 + 1)
    
    iou = interArea / float(boxAArea + boxBArea - interArea)

    print(iou)

but i obtain for example these results:

1.7540044296738415
0.6296533530603247
0.5313443694664705
0.6413727857109087

How i know is the two roi overlap or no?

Change ymaxA and xmaxA variables function max to min .

    ymaxA = min(coordenadas_A[2]*1024,coordenadas_B[2]*1024)
    xmaxA = min(coordenadas_A[3]*1024,coordenadas_B[3]*1024)

... instead of

    ymaxA = max(coordenadas_A[2]*1024,coordenadas_B[2]*1024)
    xmaxA = max(coordenadas_A[3]*1024,coordenadas_B[3]*1024)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM