enggen / Deep-Learning-Coursera

Deep Learning Specialization by Andrew Ng, deeplearning.ai.
1.65k stars 1.33k forks source link

Update Autonomous driving application - Car detection - v1.ipynb #4

Open aissam-out opened 5 years ago

aissam-out commented 5 years ago

In order to compute the intersection area, you need to make sure the height and width of the intersection are positive, otherwise the intersection area should be zero.

pradumna-gautam commented 4 years ago

Correct Code -

Calculate the (yi1, xi1, yi2, xi2) coordinates of the intersection of box1 and box2. Calculate its Area.

### START CODE HERE ### (≈ 7 lines)
yi1 = max(box1[1], box2[1])
xi1 = max(box1[0], box2[0])
yi1 = max(box1[1], box2[1])
xi2 = min(box1[2], box2[2])
yi2 = min(box1[3], box2[3])
inter_area = (xi2 - xi1)*(yi2 - yi1)
inter_area = max((xi2 - xi1), 0)*max((yi2 - yi1), 0)
### END CODE HERE ###    

It will give you following results :

iou for intersecting boxes = 0.14285714285714285 iou for non-intersecting boxes = 0.0 iou for boxes that only touch at vertices = 0.0 iou for boxes that only touch at edges = 0.0