2 if pyjevois.pro:
import libjevoispro
as jevois
3 else:
import libjevois
as jevois
42 self.
classes = jevois.Parameter(self,
'classes',
'str',
43 "Path to text file with names of object classes",
47 self.
nms = jevois.Parameter(self,
'nms',
'float',
48 "Non-maximum suppression intersection-over-union threshold in percent",
51 self.
maxnbox = jevois.Parameter(self,
'maxnbox',
'uint',
52 "Max number of top-scoring boxes to report",
55 self.
cthresh = jevois.Parameter(self,
'cthresh',
'float',
56 "Detection/classification score threshold, in percent confidence",
68 jevois.LINFO(f
"Loading {filename}...")
69 f = open(pyjevois.share +
'/' + filename,
'rt')
75 num_classes = scores.shape[1]
76 bboxes = np.broadcast_to(bboxes[:,
None], (bboxes.shape[0], num_classes, 4), )
77 valid_mask = scores > score_th
78 bboxes = bboxes[valid_mask]
79 scores = scores[valid_mask]
81 np_labels = valid_mask.nonzero()[1]
83 indices = cv2.dnn.NMSBoxes(bboxes.tolist(), scores.tolist(), score_th, nms_th)
87 indices = indices[:max_num]
90 bboxes = bboxes[indices]
91 scores = scores[indices]
92 np_labels = np_labels[indices]
93 return bboxes, scores, np_labels
95 return np.array([]), np.array([]), np.array([])
100 batch_size = bboxes.shape[0]
101 for i
in range(batch_size):
102 if not bboxes[i].shape[0]:
continue
103 bboxes, scores, class_ids = self.
multiclass_nms(bboxes[i], scores[i], score_th, nms_th, self.
maxnbox.get())
105 return bboxes, scores, class_ids
114 if (len(outs) != 2): jevois.LFATAL(
"Need 2 outputs: scores, bboxes")
121 bw, bh = preproc.blobsize(0)
124 self.
nms.get() * 0.01)
133 x1 =
float(min(bw - 1, max(0, x1)))
134 x2 =
float(min(bw - 1, max(0, x2)))
135 y1 =
float(min(bh - 1, max(0, y1)))
136 y2 =
float(min(bh - 1, max(0, y2)))
139 x1, y1 = preproc.b2i(x1, y1, 0)
140 x2, y2 = preproc.b2i(x2, y2, 0)
142 self.
boxes.append( [x1, y1, x2, y2] )
150 if self.
classmap is None or id < 0
or id >= len(self.
classmap): categ =
'unknown'
153 color = jevois.stringToRGBA(categ, 255)
155 return ( (
"%s: %.2f" % (categ, conf * 100.0)), color & 0xffffffff)
168 def report(self, outimg, helper, overlay, idle):
171 if outimg
is not None:
175 x1, y1, x2, y2 = self.
boxes[i]
176 jevois.drawRect(outimg, x1, y1, x2 - x1, y2 - y1, 2, jevois.YUYV.LightGreen)
177 jevois.writeText(outimg, label, x1 + 6, y1 + 2, jevois.YUYV.LightGreen, jevois.Font.Font10x20)
180 if helper
is not None:
184 x1, y1, x2, y2 = self.
boxes[i]
185 helper.drawRect(x1, y1, x2, y2, color & 0xffffffff,
True)
186 helper.drawText(x1 + 3, y1 + 3, label, color & 0xffffffff)