11 def __init__(self, modelPath, charsetPath, backendId=0, targetId=0):
32 return self.__class__.__name__
34 def _load_charset(self, charsetPath):
36 with open(charsetPath,
'r')
as f:
50 def _preprocess(self, image, rbbox):
52 vertices = rbbox.reshape((4, 2)).astype(np.float32)
54 rotationMatrix = cv.getPerspectiveTransform(vertices, self.
_targetVertices)
55 cropped = cv.warpPerspective(image, rotationMatrix, self.
_inputSize)
60 cropped = cv.cvtColor(cropped, cv.COLOR_BGR2GRAY)
62 return cv.dnn.blobFromImage(cropped, size=self.
_inputSize, mean=127.5, scalefactor=1 / 127.5)
69 self.
_model.setInput(inputBlob)
70 outputBlob = self.
_model.forward()
77 def _postprocess(self, outputBlob):
78 '''Decode charaters from outputBlob
81 for i
in range(outputBlob.shape[0]):
82 c = np.argmax(outputBlob[i][0])
90 for i
in range(len(text)):
91 if text[i] !=
'-' and (
not (i > 0
and text[i] == text[i - 1])):
92 char_list.append(text[i])
93 return ''.
join(char_list)