57 self.
mean = [104, 117, 123]
64 backend = cv.dnn.DNN_BACKEND_OPENCV
65 target = cv.dnn.DNN_TARGET_CPU
68 if (model ==
'SqueezeNet'):
69 classnames = pyjevois.share +
'/opencv-dnn/classification/synset_words.txt'
70 modelname = pyjevois.share +
'/opencv-dnn/classification/squeezenet_v1.1.caffemodel'
71 configname = pyjevois.share +
'/opencv-dnn/classification/squeezenet_v1.1.prototxt'
75 with open(classnames,
'rt')
as f:
76 self.
classes = f.read().rstrip(
'\n').split(
'\n')
79 self.
net = cv.dnn.readNet(modelname, configname)
80 self.
net.setPreferableBackend(backend)
81 self.
net.setPreferableTarget(target)
88 frame = inframe.getCvBGR()
91 frameHeight = frame.shape[0]
92 frameWidth = frame.shape[1]
98 self.
net.setInput(blob)
99 out = self.
net.forward()
103 classId = np.argmax(out)
104 confidence = out[classId]
107 msgbox = np.zeros((24, frame.shape[1], 3), dtype = np.uint8) + 80
110 rlabel =
'%s: %.2f' % (self.
classes[classId]
if self.
classes else 'Class #%d' % classId, confidence*100)
112 cv.putText(msgbox, rlabel, (3, 15), cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1, cv.LINE_AA)
115 cv.putText(frame,
'JeVois Classification DNN - ' + self.
model, (3, 15),
116 cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1, cv.LINE_AA)
117 t, _ = self.
net.getPerfProfile()
118 fps = self.
timer.stop()
119 label = fps +
', %dms' % (t * 1000.0 / cv.getTickFrequency())
120 cv.putText(frame, label, (3, frameHeight-5), cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1, cv.LINE_AA)
123 frame = np.vstack((frame, msgbox))
126 outframe.sendCv(frame)