Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
P0: 7.215377000000e+02 0.000000000000e+00 6.095593000000e+02 0.000000000000e+00 0.000000000000e+00 7.215377000000e+02 1.728540000000e+02 0.000000000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 0.000000000000e+00 | ||
P1: 7.215377000000e+02 0.000000000000e+00 6.095593000000e+02 -3.875744000000e+02 0.000000000000e+00 7.215377000000e+02 1.728540000000e+02 0.000000000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 0.000000000000e+00 | ||
P2: 7.215377000000e+02 0.000000000000e+00 6.095593000000e+02 4.485728000000e+01 0.000000000000e+00 7.215377000000e+02 1.728540000000e+02 2.163791000000e-01 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 2.745884000000e-03 | ||
P3: 7.215377000000e+02 0.000000000000e+00 6.095593000000e+02 -3.395242000000e+02 0.000000000000e+00 7.215377000000e+02 1.728540000000e+02 2.199936000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 2.729905000000e-03 | ||
R0_rect: 9.999239000000e-01 9.837760000000e-03 -7.445048000000e-03 -9.869795000000e-03 9.999421000000e-01 -4.278459000000e-03 7.402527000000e-03 4.351614000000e-03 9.999631000000e-01 | ||
Tr_velo_to_cam: 7.533745000000e-03 -9.999714000000e-01 -6.166020000000e-04 -4.069766000000e-03 1.480249000000e-02 7.280733000000e-04 -9.998902000000e-01 -7.631618000000e-02 9.998621000000e-01 7.523790000000e-03 1.480755000000e-02 -2.717806000000e-01 | ||
Tr_imu_to_velo: 9.999976000000e-01 7.553071000000e-04 -2.035826000000e-03 -8.086759000000e-01 -7.854027000000e-04 9.998898000000e-01 -1.482298000000e-02 3.195559000000e-01 2.024406000000e-03 1.482454000000e-02 9.998881000000e-01 -7.997231000000e-01 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
P0: 7.215377000000e+02 0.000000000000e+00 6.095593000000e+02 0.000000000000e+00 0.000000000000e+00 7.215377000000e+02 1.728540000000e+02 0.000000000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 0.000000000000e+00 | ||
P1: 7.215377000000e+02 0.000000000000e+00 6.095593000000e+02 -3.875744000000e+02 0.000000000000e+00 7.215377000000e+02 1.728540000000e+02 0.000000000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 0.000000000000e+00 | ||
P2: 7.215377000000e+02 0.000000000000e+00 6.095593000000e+02 4.485728000000e+01 0.000000000000e+00 7.215377000000e+02 1.728540000000e+02 2.163791000000e-01 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 2.745884000000e-03 | ||
P3: 7.215377000000e+02 0.000000000000e+00 6.095593000000e+02 -3.395242000000e+02 0.000000000000e+00 7.215377000000e+02 1.728540000000e+02 2.199936000000e+00 0.000000000000e+00 0.000000000000e+00 1.000000000000e+00 2.729905000000e-03 | ||
R0_rect: 9.999239000000e-01 9.837760000000e-03 -7.445048000000e-03 -9.869795000000e-03 9.999421000000e-01 -4.278459000000e-03 7.402527000000e-03 4.351614000000e-03 9.999631000000e-01 | ||
Tr_velo_to_cam: 7.533745000000e-03 -9.999714000000e-01 -6.166020000000e-04 -4.069766000000e-03 1.480249000000e-02 7.280733000000e-04 -9.998902000000e-01 -7.631618000000e-02 9.998621000000e-01 7.523790000000e-03 1.480755000000e-02 -2.717806000000e-01 | ||
Tr_imu_to_velo: 9.999976000000e-01 7.553071000000e-04 -2.035826000000e-03 -8.086759000000e-01 -7.854027000000e-04 9.998898000000e-01 -1.482298000000e-02 3.195559000000e-01 2.024406000000e-03 1.482454000000e-02 9.998881000000e-01 -7.997231000000e-01 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
from scipy.spatial import ConvexHull | ||
import numpy as np | ||
|
||
def boxoverlap(a,b,criterion="union"): | ||
""" | ||
boxoverlap computes intersection over union for bbox a and b in KITTI format. | ||
If the criterion is 'union', overlap = (a inter b) / a union b). | ||
If the criterion is 'a', overlap = (a inter b) / a, where b should be a dontcare area. | ||
""" | ||
|
||
x1 = max(a.x1, b.x1) | ||
y1 = max(a.y1, b.y1) | ||
x2 = min(a.x2, b.x2) | ||
y2 = min(a.y2, b.y2) | ||
|
||
w = x2-x1 | ||
h = y2-y1 | ||
|
||
if w<=0. or h<=0.: | ||
return 0. | ||
inter = w*h | ||
aarea = (a.x2-a.x1) * (a.y2-a.y1) | ||
barea = (b.x2-b.x1) * (b.y2-b.y1) | ||
# intersection over union overlap | ||
if criterion.lower()=="union": | ||
o = inter / float(aarea+barea-inter) | ||
elif criterion.lower()=="a": | ||
o = float(inter) / float(aarea) | ||
else: | ||
raise TypeError("Unkown type for criterion") | ||
return o | ||
|
||
|
||
def polygon_clip(subjectPolygon, clipPolygon): | ||
""" Clip a polygon with another polygon. | ||
Ref: https://rosettacode.org/wiki/Sutherland-Hodgman_polygon_clipping#Python | ||
Args: | ||
subjectPolygon: a list of (x,y) 2d points, any polygon. | ||
clipPolygon: a list of (x,y) 2d points, has to be *convex* | ||
Note: | ||
**points have to be counter-clockwise ordered** | ||
Return: | ||
a list of (x,y) vertex point for the intersection polygon. | ||
""" | ||
def inside(p): | ||
return(cp2[0]-cp1[0])*(p[1]-cp1[1]) > (cp2[1]-cp1[1])*(p[0]-cp1[0]) | ||
|
||
def computeIntersection(): | ||
dc = [ cp1[0] - cp2[0], cp1[1] - cp2[1] ] | ||
dp = [ s[0] - e[0], s[1] - e[1] ] | ||
n1 = cp1[0] * cp2[1] - cp1[1] * cp2[0] | ||
n2 = s[0] * e[1] - s[1] * e[0] | ||
n3 = 1.0 / (dc[0] * dp[1] - dc[1] * dp[0]) | ||
return [(n1*dp[0] - n2*dc[0]) * n3, (n1*dp[1] - n2*dc[1]) * n3] | ||
|
||
outputList = subjectPolygon | ||
cp1 = clipPolygon[-1] | ||
|
||
for clipVertex in clipPolygon: | ||
cp2 = clipVertex | ||
inputList = outputList | ||
outputList = [] | ||
s = inputList[-1] | ||
|
||
for subjectVertex in inputList: | ||
e = subjectVertex | ||
if inside(e): | ||
if not inside(s): | ||
outputList.append(computeIntersection()) | ||
outputList.append(e) | ||
elif inside(s): | ||
outputList.append(computeIntersection()) | ||
s = e | ||
cp1 = cp2 | ||
if len(outputList) == 0: | ||
return None | ||
return(outputList) | ||
|
||
|
||
def poly_area(x,y): | ||
""" Ref: http://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates """ | ||
return 0.5*np.abs(np.dot(x,np.roll(y,1))-np.dot(y,np.roll(x,1))) | ||
|
||
def convex_hull_intersection(p1, p2): | ||
""" Compute area of two convex hull's intersection area. | ||
p1,p2 are a list of (x,y) tuples of hull vertices. | ||
return a list of (x,y) for the intersection and its volume | ||
""" | ||
inter_p = polygon_clip(p1,p2) | ||
if inter_p is not None: | ||
hull_inter = ConvexHull(inter_p) | ||
return inter_p, hull_inter.volume | ||
else: | ||
return None, 0.0 | ||
|
||
def box3d_vol(corners): | ||
''' corners: (8,3) no assumption on axis direction ''' | ||
a = np.sqrt(np.sum((corners[0,:] - corners[1,:])**2)) | ||
b = np.sqrt(np.sum((corners[1,:] - corners[2,:])**2)) | ||
c = np.sqrt(np.sum((corners[0,:] - corners[4,:])**2)) | ||
return a*b*c | ||
|
||
def box3d_iou(corners1, corners2, criterion='union'): | ||
''' Compute 3D bounding box IoU. | ||
Input: | ||
corners1: numpy array (8,3), assume up direction is negative Y | ||
corners2: numpy array (8,3), assume up direction is negative Y | ||
Output: | ||
iou: 3D bounding box IoU | ||
iou_2d: bird's eye view 2D bounding box IoU | ||
todo (rqi): add more description on corner points' orders. | ||
''' | ||
# corner points are in counter clockwise order | ||
rect1 = [(corners1[i,0], corners1[i,2]) for i in range(3,-1,-1)] | ||
rect2 = [(corners2[i,0], corners2[i,2]) for i in range(3,-1,-1)] | ||
area1 = poly_area(np.array(rect1)[:,0], np.array(rect1)[:,1]) | ||
area2 = poly_area(np.array(rect2)[:,0], np.array(rect2)[:,1]) | ||
inter, inter_area = convex_hull_intersection(rect1, rect2) | ||
|
||
ymax = min(corners1[0,1], corners2[0,1]) | ||
ymin = max(corners1[4,1], corners2[4,1]) | ||
inter_vol = inter_area * max(0.0, ymax-ymin) | ||
vol1 = box3d_vol(corners1) | ||
vol2 = box3d_vol(corners2) | ||
if criterion.lower() == 'union': | ||
iou = inter_vol / (vol1 + vol2 - inter_vol) | ||
iou_2d = inter_area/(area1+area2-inter_area) | ||
elif criterion.lower() == 'a': | ||
iou = inter_vol / vol1 | ||
iou_2d = inter_area / area1 | ||
else: | ||
raise TypeError("Unkown type for criterion") | ||
return iou, iou_2d | ||
|
||
def roty(t): | ||
''' Rotation about the y-axis. ''' | ||
c = np.cos(t) | ||
s = np.sin(t) | ||
return np.array([[c, 0, s], | ||
[0, 1, 0], | ||
[-s, 0, c]]) | ||
|
||
def compute_box_3d(obj): | ||
''' Takes an object and a projection matrix (P) and projects the 3d | ||
bounding box into the image plane. | ||
Returns: | ||
corners_2d: (8,2) array in left image coord. | ||
corners_3d: (8,3) array in in rect camera coord. | ||
''' | ||
# compute rotational matrix around yaw axis | ||
R = roty(obj.yaw) | ||
|
||
# 3d bounding box dimensions | ||
l = obj.l | ||
w = obj.w | ||
h = obj.h | ||
|
||
# 3d bounding box corners | ||
x_corners = [l/2,l/2,-l/2,-l/2,l/2,l/2,-l/2,-l/2]; | ||
y_corners = [0,0,0,0,-h,-h,-h,-h]; | ||
z_corners = [w/2,-w/2,-w/2,w/2,w/2,-w/2,-w/2,w/2]; | ||
|
||
# rotate and translate 3d bounding box | ||
corners_3d = np.dot(R, np.vstack([x_corners,y_corners,z_corners])) | ||
#print corners_3d.shape | ||
corners_3d[0,:] = corners_3d[0,:] + obj.X | ||
corners_3d[1,:] = corners_3d[1,:] + obj.Y | ||
corners_3d[2,:] = corners_3d[2,:] + obj.Z | ||
# print('cornsers_3d: ', corners_3d) | ||
|
||
return np.transpose(corners_3d) | ||
|
||
def box3doverlap(aa, bb, criterion='union'): | ||
aa_3d = compute_box_3d(aa) | ||
bb_3d = compute_box_3d(bb) | ||
|
||
iou3d, iou2d = box3d_iou(aa_3d, bb_3d, criterion=criterion) | ||
# print(iou3d) | ||
# print(iou2d) | ||
return iou3d |