11 def __init__(self, modelPath, backendId=0, targetId=0):
23 self.
_mean = np.array([0.5, 0.5, 0.5])[np.newaxis, np.newaxis, :]
24 self.
_std = np.array([0.5, 0.5, 0.5])[np.newaxis, np.newaxis, :]
28 return self.__class__.__name__
38 def _preprocess(self, image):
39 image = image.astype(np.float32, copy=
False) / 255.0
42 return cv.dnn.blobFromImage(image)
45 assert image.shape[0] == self.
_inputSize[1],
'{} (height of input image) != {} (preset height)'.format(image.shape[0], self.
_inputSize[1])
46 assert image.shape[1] == self.
_inputSize[0],
'{} (width of input image) != {} (preset width)'.format(image.shape[1], self.
_inputSize[0])
60 def _postprocess(self, outputBlob):
61 result = np.argmax(outputBlob[0], axis=1).astype(np.uint8)