:class: bounding box for detection result, inherited from BoxBase :ivar float score: detection score (for one class) of bounding box :ivar int matched: if matched with a groundtruth. 0 for unmatched (default); 1 for matched; -1 for matched with an igonred groundtruth
| 215 | """ |
| 216 | |
| 217 | class DetBox(BoxBase): |
| 218 | """ |
| 219 | :class: bounding box for detection result, inherited from BoxBase |
| 220 | :ivar float score: detection score (for one class) of bounding box |
| 221 | :ivar int matched: if matched with a groundtruth. 0 for unmatched (default); 1 for matched; -1 for matched with an igonred groundtruth |
| 222 | """ |
| 223 | def __init__(self, x=0.0, y=0.0, w=0.0, h=0.0, tag=None, score=0.0, color=None): |
| 224 | super(DetBox, self).__init__(x, y, w, h, tag) |
| 225 | self.score = score |
| 226 | self.matched = 0 # 0 for unmatched / 1 for matched / -1 for matched with ignored gt |
| 227 | self.color = color |
| 228 | |
| 229 | def parseOdf(self, odf): |
| 230 | """ |
| 231 | :meth: read the object from a dict |
| 232 | :param dict odf: a dict with "box" and "score" keys, e.g., odf = {"box": [5,5,20,50], "score": 0.4} |
| 233 | """ |
| 234 | super(DetBox, self).parseOdf(odf) |
| 235 | if "score" in odf: |
| 236 | self.score = odf["score"] |
| 237 | self.matched = 0 |
| 238 | def parseOdfbyname(self,odf,name): |
| 239 | |
| 240 | super(DetBox,self).parseOdfbyname(odf,name) |
| 241 | if "score" in odf: |
| 242 | self.score = odf["score"] |
| 243 | self.matched = 0 |
| 244 | def dumpOdf(self): |
| 245 | """ |
| 246 | :meth: dump the object into a dict |
| 247 | :return: a dict with "box" and "score" keys |
| 248 | """ |
| 249 | odf = super(DetBox, self).dumpOdf() |
| 250 | odf["score"] = self.score |
| 251 | return odf |
| 252 | |
| 253 | def _getDrawColor(self): |
| 254 | """ |
| 255 | :meth: get the color for detection box. Blue for unmatched (self.matched=0); green for matched (self.matched=1); white for matched with ignored groundtruth (self.matched=-1) |
| 256 | """ |
| 257 | if self.color is not None: |
| 258 | return self.color |
| 259 | color = (0, 255, 0) # green for matched dt (unignored) |
| 260 | """ |
| 261 | if self.matched == 0: |
| 262 | color = (255, 0, 0) # blue for unmatched dt |
| 263 | elif self.matched == 1: |
| 264 | color = (0, 255, 0) # green for matched dt (unignored) |
| 265 | elif self.matched == -1: |
| 266 | color = (255, 255, 255) # white for matched dt (ignored) |
| 267 | """ |
| 268 | return color |
| 269 | |
| 270 | |
| 271 | class DetBoxGT(BoxBase): |
no outgoing calls