def ocr_images( images ): model = models.load_model( opt.crnn ) maxWidth = max([i.shape[1] for i in images ]) images = [ np.pad( i, [(2, 1), (0, maxWidth - i.shape[1] ), (0,0)], mode='constant', constant_values=1) for i in images ] out = model.predict( np.array(images) ) out = out.argmax(2) textResults = [ decodeStr( i, raw=False ) for i in out ] return textResults
def ocr_images(model, images): # import pdb; pdb.set_trace(); # from IPython import embed; embed() out = [] for img in images: res = model.predict(np.array([img])) res = res.argmax(2) out.append(decodeStr(res[0], raw=False)) return out
def testEncoding(self, opt): """ function for self testing. Encode each wrod, then decode it back """ goodWords = [] words = getTrainingTexts(self.WORD_LIST_FILE) for w in words: try: enc, encSize = encodeStr(w) goodWords.append(w) except Exception as e: print('Error encoding "%s"' % w, e) continue dec = decodeStr(enc) if (w != dec): raise ValueError('Encoding failed "%s" != "%s"' % (w, dec)) if (opt.update): writeFile(self.WORD_LIST_FILE, '\n'.join(goodWords))