def run(self): """Execute of Code logic""" source, dest = self._inputs dest = trim_file_ext(self._inputs[1]) print('New Dest {}'.format(dest)) self._inputs = (source, dest) super().run()
def main(image_filename, image_dir=None): """ convert image -> text file :param image_filename: filename with path :return: """ source_image = image_filename image = cv2.imread(source_image, 0) line_segments = get_line_segments(image) line_image_offset = 0 i = 1 if not image_dir: # TODO: Need to remove config usage from here image_dir = os.path.join(config.TEXT_IMAGES, trim_file_ext(os.path.basename(source_image))) if os.path.isdir(image_dir): print('Skipping the run as {} already exists'.format(image_dir)) return else: os.mkdir(image_dir) for start, end in line_segments: if abs(start - end) < 10: continue text_image = image[start - line_image_offset:end + line_image_offset, :] plt.imsave(os.path.join(image_dir, str(i) + '.png'), text_image) i += 1
def update_data(image=None): image_key = trim_file_ext(image) if image_key in GetNewImage.pending_images: GetNewImage.pending_images.remove(image_key) GetNewImage.completed_images.append(image_key) del GetNewImage.receipt_images[image_key] print('Image Annotations Done for {}'.format(image))
def main(source_file, destination_file=None): img = cv2.imread(source_file) out_path = trim_file_ext(source_file) + '.tesseract.txt' text = pytesseract.image_to_string(img, lang='eng', config=config.TESSERACT_CONFIG) with open(out_path, "w") as fd: fd.write(string_parser(text)) return out_path
def get_specific_image(image_file): image_name = trim_file_ext(image_file) send_info = { 'id': GetNewImage.receipt_images[image_name]['file'], # 'url': GetNewImage.receipt_images[image_name]['url'], 'url': get_image_url(GetNewImage.receipt_images[image_name]), 'folder': '', "annotations": [] } return send_info
def rotate_image_with_east(img_filename, save_file=None): image = plt.imread(img_filename) text_filename = os.path.join( os.path.dirname(img_filename), trim_file_ext(os.path.basename(img_filename)) + '.txt') raw_data, bag = read_data(text_filename) new_plot_points = trim_outliers1(raw_data) cnt = np.array(new_plot_points) rect = cv2.minAreaRect(cnt) box = cv2.boxPoints(rect) box = np.int0(box) warped = four_point_transform(image, box) if save_file: plt.imsave(save_file, warped) else: plt.figure(figsize=(10, 10)) plt.imshow(warped)
def gen_cropper_binarisation(image_name): image_id = trim_file_ext(image_name) _regenerate_binarisation_images(image_id) return 'ok - _generate_binarisation_images'
def update_cropper_data(image_file): image_id = trim_file_ext(image_file) GetNewImage.receipt_images[image_id]['cropper_url'] = os.path.join(config.CROPPER_ROOT_DIR, image_file)
def update_binarisation_data(image_file): image_id = trim_file_ext(image_file) GetNewImage.receipt_images[image_id]['binarisation_url'] = os.path.join(config.BINARIZE_ROOT_DIR, image_file)