-
Notifications
You must be signed in to change notification settings - Fork 0
/
piezas.py
155 lines (131 loc) · 3.76 KB
/
piezas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import numpy as np
import numpy.matlib as matlib
import matplotlib.pyplot as plt
import utility as utl
import skimage.util as skutl
from scipy.misc import imresize
from scipy.ndimage import rotate as imrotate
import cv2
class ObjectType:
Dontcare, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16 = range(17);
def __init__(self):
pass
class DetectionGT:
"""
This class is the data ground-truth
"""
# default class mappings
OBJECT_TYPES = {
'p1': ObjectType.p1,
'p2': ObjectType.p2,
'p3': ObjectType.p3,
'p4': ObjectType.p4,
'p5': ObjectType.p5,
'p6': ObjectType.p6,
'p7': ObjectType.p7,
'p8': ObjectType.p8,
'p9': ObjectType.p9,
'p10': ObjectType.p10,
'p11': ObjectType.p11,
'p12': ObjectType.p12,
'p13': ObjectType.p13,
'p14': ObjectType.p14,
'p15': ObjectType.p15,
'p16': ObjectType.p16
}
def __init__(self):
self.stype = ''
self.truncated = 0
self.occlusion = 0
self.angle = 0
self.height = 0
self.width = 0
self.length = 0
self.locx = 0
self.locy = 0
self.locz = 0
self.roty = 0
self.bbox = np.zeros((2,2))
def assignment(self, o):
self.stype = o.stype;
self.truncated = o.truncation;
self.occlusion = 0;
self.angle = 0;
self.height = 0;
self.width = 0;
self.length = 0;
self.locx = 0;
self.locy = 0;
self.locz = 0;
self.roty = 0;
self.bbox = o.bbox;
self.object = self.OBJECT_TYPES.get(o.stype, ObjectType.Dontcare);
def gt_to_kitti_format(self):
'''
Convert to kitti format
'''
result = [
# set label, truncation, occlusion
self.stype,
np.bool(self.truncated).numerator,
self.occlusion,
self.angle,
# set 2D bounding box in 0-based C++ coordinates
self.bbox[0,0],
self.bbox[0,1],
self.bbox[1,0],
self.bbox[1,1],
# set 3D bounding box
self.height,
self.width,
self.length,
self.locx,
self.locy,
self.locz,
self.roty
];
return result;
@classmethod
def lmdb_format_length(cls):
"""
width of an LMDB datafield returned by the gt_to_lmdb_format function.
:return:
"""
return 16
def gt_to_lmdb_format(self):
"""
For storage of a bbox ground truth object into a float32 LMDB.
Sort-by attribute is always the last value in the array.
"""
result = [
# bbox in x,y,w,h format:
self.bbox[0,0],
self.bbox[0,1],
self.bbox[1,0] - self.bbox[0,0],
self.bbox[1,1] - self.bbox[0,1],
# alpha angle:
self.angle,
# class number:
self.object,
0,
# Y axis rotation:
self.roty,
# bounding box attributes:
self.truncated,
self.occlusion,
# object dimensions:
self.length,
self.width,
self.height,
self.locx,
self.locy,
# depth (sort-by attribute):
self.locz,
]
assert(len(result) is self.lmdb_format_length())
return result
class Piece(object):
"Piece for mcc generator result"
stype = ''
bbox = np.zeros((4,2));
truncation = False;