Last active
June 6, 2020 08:36
-
-
Save daisenryaku/91e6f6d78f49f67602d21dc57d494c60 to your computer and use it in GitHub Desktop.
3D IoU (Intersection over Union)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 3D IoU python Implementation | |
# [IoU](https://www.pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/) | |
def IoU(box0, box1): | |
# box0: [x, y, z, d] | |
r0 = box0[3] / 2 | |
s0 = box0[:3] - r0 | |
e0 = box0[:3] + r0 | |
r1 = box1[3] / 2 | |
s1 = box1[:3] - r1 | |
e1 = box1[:3] + r1 | |
overlap = [max(0, min(e0[i], e1[i]) - max(s0[i], s1[i])) for i in range(3)] | |
intersection = reduce(lambda x,y:x*y, overlap) | |
union = pow(box0[3], 3) + pow(box1[3], 3) - intersection | |
return intersection / union |
Not able to understand since box0[3]=d what does this mean?
Not able to understand since box0[3]=d what does this mean?
This box is only a cube which it has a same width, length, and height.
The d
in each box represents a length while (x,y,z)
represents a centroid of the box.
Therefore, r = box[3] = d / 2
gives you the half of the dimension.
For example, if a box has a centroid at (0,0,0)
with d = 4
, r = d/2 = 2
and you simply add r
into the centroid to get the upper bound, and subtract to get the lower bound of a given box.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you elaborate how is the box encoded?
Thank you!