51 font = cv.FONT_HERSHEY_PLAIN
53 white = (255, 255, 255)
56 if not hasattr(self,
'net'):
57 self.
classes = [
"neutral",
"happiness",
"surprise",
"sadness",
"anger",
"disgust",
60 self.
net = cv.dnn.readNet(pyjevois.share +
"/opencv-dnn/classification/emotion_ferplus.onnx",
'')
61 self.
net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)
62 self.
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
65 frame = inframe.getCvBGR()
68 frameHeight = frame.shape[0]
69 frameWidth = frame.shape[1]
70 mid = int((frameWidth - 110) / 2) + 110
71 leng = frameWidth - mid - 6
75 gframe = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
79 self.
net.setInput(blob)
80 out = self.
net.forward()
83 msgbox = np.zeros((96, frame.shape[1], 3), dtype = np.uint8) + 80
89 if conf > maxconf: conf = maxconf
90 if conf < -maxconf: conf = -maxconf
91 cv.putText(msgbox, self.
classes[i] +
':', (3, 11*(i+1)), font, siz, white, 1, cv.LINE_AA)
92 rlabel =
'%+6.1f' % conf
93 cv.putText(msgbox, rlabel, (76, 11*(i+1)), font, siz, white, 1, cv.LINE_AA)
94 cv.line(msgbox, (mid, 11*i+6), (mid + int(conf*leng/maxconf), 11*i+6), white, 4)
97 cv.putText(frame,
'JeVois Emotion DNN - ' + self.
model, (3, 15),
98 cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1, cv.LINE_AA)
99 t, _ = self.
net.getPerfProfile()
100 fps = self.
timer.stop()
101 label = fps +
', %dms' % (t * 1000.0 / cv.getTickFrequency())
102 cv.putText(frame, label, (3, frameHeight-5), cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1, cv.LINE_AA)
105 frame = np.vstack((frame, msgbox))
108 outframe.sendCv(frame)