2 if pyjevois.pro:
import libjevoispro
as jevois
3 else:
import libjevois
as jevois
52 self.
classoffset = jevois.Parameter(self,
'classoffset',
'int',
53 "Offset to apply to class indices",
56 self.
classes = jevois.Parameter(self,
'classes',
'str',
57 "Path to text file with names of object classes",
61 self.
detecttype = jevois.Parameter(self,
'detecttype',
'str',
62 "Type of detection output format -- only RAWYOLO supported in Python",
66 self.
nms = jevois.Parameter(self,
'nms',
'float',
67 "Non-maximum suppression intersection-over-union threshold in percent",
70 self.
maxnbox = jevois.Parameter(self,
'maxnbox',
'uint',
71 "Max number of top-scoring boxes to report (for YOLO flavors, "
72 "this is the max for each scale)",
75 self.
cthresh = jevois.Parameter(self,
'cthresh',
'float',
76 "Classification threshold, in percent confidence",
79 self.
dthresh = jevois.Parameter(self,
'dthresh',
'float',
80 "Detection box threshold (in percent confidence) above which "
81 "predictions will be reported. Not all networks use a separate box threshold, "
82 "many only use one threshold confidence threshold (cthresh parameter). The YOLO "
83 "family is an example that uses both box and classification confidences",
100 jevois.LINFO(f
"Loading {filename}...")
101 f = open(pyjevois.share +
'/' + filename,
'rt')
108 jevois.LFATAL(f
"Invalid detecttype {dt} -- only RAWYOLO is supported in Python")
116 if (len(outs) == 0): jevois.LFATAL(
"No outputs received, we need at least one.");
124 self.imagew, self.
imageh = preproc.imagesize()
131 bw, bh = preproc.blobsize(0)
135 classids, confs, boxes = self.
yolopp.
yolo(outs,
144 indices = cv2.dnn.NMSBoxes(boxes, confs, self.
cthresh.get() * 0.01, self.
nms.get() * 0.01)
148 x, y, w, h = boxes[i]
151 x1 = min(bw - 1, max(0, x))
152 x2 = min(bw - 1, max(0, x + w))
153 y1 = min(bh - 1, max(0, y))
154 y2 = min(bh - 1, max(0, y + h))
157 x1, y1 = preproc.b2i(x1, y1, 0)
158 x2, y2 = preproc.b2i(x2, y2, 0)
160 self.
boxes.append( [x1, y1, x2, y2] )
165 self.
classIds = [classids[i]
for i
in indices]
171 if self.
classmap is None or id < 0
or id >= len(self.
classmap): categ =
'unknown'
174 color = jevois.stringToRGBA(categ, 255)
176 return ( (
"%s: %.2f" % (categ, conf * 100.0)), color & 0xffffffff)
189 def report(self, outimg, helper, overlay, idle):
192 if outimg
is not None:
196 x1, y1, x2, y2 = self.
boxes[i]
197 jevois.drawRect(outimg, x1, y1, x2 - x1, y2 - y1, 2, jevois.YUYV.LightGreen)
198 jevois.writeText(outimg, label, x1 + 6, y1 + 2, jevois.YUYV.LightGreen, jevois.Font.Font10x20)
201 if helper
is not None:
205 x1, y1, x2, y2 = self.
boxes[i]
206 helper.drawRect(x1, y1, x2, y2, color & 0xffffffff,
True)
207 helper.drawText(x1 + 3, y1 + 3, label, color & 0xffffffff)