def recognize_text(self, img, task=""): word_list = [] print("Image Processing Started") img_handler = ImageHandler() words = img_handler.split_text(img, task) for word in words: img = cv2.cvtColor(word, cv2.COLOR_BGR2GRAY) # img = img_handler.preprocess_normal_handwriting(img) img = img_handler.preprocess(img, self.img_size) word_list.append(img) # cv2.imshow('word', word) # cv2.waitKey(0) print("Image Processing Finished") print("Recognizing Text Started") batch = Batch(None, word_list) recognized_list = self.model.batch_test(batch) print('Image Text: ', recognized_list) text = '' for i in recognized_list: text += i + ' ' return text
def get_next(self): labels = [] imgs = [] batch_range = range(self.current_index, self.current_index + self.batch_size) for i in batch_range: sample = self.samples[i] labels.append(sample.label) img = cv2.imread(sample.file_path, cv2.IMREAD_GRAYSCALE) img_handler = ImageHandler() img = img_handler.preprocess(img, self.img_size) imgs.append(img) self.current_index += self.batch_size return Batch(labels, imgs)
def test_address(self, img, task=""): word_list = [] img_handler = ImageHandler() words = img_handler.split_text(img, task) for word in words: img = cv2.cvtColor(word, cv2.COLOR_BGR2GRAY) # img = img_handler.preprocess_normal_handwriting(img) img = img_handler.preprocess(img, self.img_size) word_list.append(img) # cv2.imshow('word', word) # cv2.waitKey(0) batch = Batch(None, word_list) recognized_list = self.model.batch_test(batch) return recognized_list