How to calculate IOU for multiple bounding boxes in one img?

Viewed 2230

Suppose there is a object detection task. There are many cars in the img. What I need to do, is to draw boxes to detect these cars. Someone else is doing the same task. My result is [car1,car2,car5,car6], someone's result is [car1,car3,car5,car5,car7].(carx is the coordinate of #x cat in this img)
Both of us only detect some of the car in the img.
Now I want to find a way evaluate the similarity between our result.
If both of us only find one car, it is easy,

def cal_iou(coordinate_x, coordinate_y):
    polygon_x = geometry.Polygon(coordinate_x)
    polygon_y = geometry.Polygon(coordinate_y)
    intersection = polygon_x.intersection(polygon_y).area
    total_area = polygon_x.area + polygon_y.area - intersection
    if total_area > 0.0:
        return float(intersection / total_area)
    return 0.0

I can compute the IoU between two boxex. What if there are more than one box in our result? I don't know which box in other's result should be compared with car1? Another way I think is to get all area in my result, and compare with other's result. But I have not find a good way to do this. plz give me some suggestion

2 Answers

The IoU between box1 to box2 is the same as box2 to box1. What I most of the time do is calculate all IoUs and pick the highest. The 2 boxes how belong to this IoU can be removed and the process can be repeated. Till all boxes are linked or the highest IoU is below the threshold

calc all box with one box and then, pick best box that's the closest box

Related