NVIDIA / retinanet-examples

Fast and accurate object detection with end-to-end GPU optimization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Positive width and height and corners2rotatedbbox(corners) function

MteaHubHug opened this issue · comments

In the function :

def _corners2rotatedbbox(corners):
centre = np.mean(np.array(corners), 0)
theta = calc_bearing(corners[0], corners[1])
rotation = np.array([[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]])
out_points = np.matmul(corners - centre, rotation) + centre
x, y = list(out_points[0,:])
w, h = list(out_points[2, :] - out_points[0, :])
return [x, y, w, h, theta]

width and height are computed like this : w, h = list(out_points[2, :] - out_points[0, :])

It is ok to just take absolute value because width and height has to be positive.
(see sketch1)
image

So, you can just change it to :
w, h = list(out_points[2, :] - out_points[0, :])
w= math.fabs(w)
h=math.fabs(h)
return [x, y, w, h, theta]

Still, I think this:
w, h = list(out_points[2, :] - out_points[0, :])
is not correct way to compute width and height (see my schetch2).
image

I think that is ok just when box is not roatated. In rotated case, it has to be :
w= math.distance(point1,point2)
h=math.distance(point2,point3)

Pls, tell me what do you think about this?
BR

Thanks, we will look into this and let you know.