From cd9920eea76ab1bb5538fb50785a36d451ca1146 Mon Sep 17 00:00:00 2001 From: vahid Date: Wed, 4 May 2022 17:01:42 +0200 Subject: [PATCH] extracting page --- qurator/eynollah/cli.py | 16 ++++++++++++---- qurator/eynollah/eynollah.py | 4 ++++ qurator/eynollah/plot.py | 4 ++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/qurator/eynollah/cli.py b/qurator/eynollah/cli.py index 18ea583..6828cc5 100644 --- a/qurator/eynollah/cli.py +++ b/qurator/eynollah/cli.py @@ -54,6 +54,12 @@ from qurator.eynollah.eynollah import Eynollah help="if a directory is given, all plots needed for documentation will be saved there", type=click.Path(exists=True, file_okay=False), ) +@click.option( + "--save_page", + "-sp", + help="if a directory is given, page crop of image will be saved there", + type=click.Path(exists=True, file_okay=False), +) @click.option( "--enable-plotting/--disable-plotting", "-ep/-noep", @@ -129,6 +135,7 @@ def main( save_layout, save_deskewed, save_all, + save_page, enable_plotting, allow_enhancement, curved_line, @@ -144,11 +151,11 @@ def main( if log_level: setOverrideLogLevel(log_level) initLogging() - if not enable_plotting and (save_layout or save_deskewed or save_all or save_images or allow_enhancement): - print("Error: You used one of -sl, -sd, -sa, -si or -ae but did not enable plotting with -ep") + if not enable_plotting and (save_layout or save_deskewed or save_all or save_page or save_images or allow_enhancement): + print("Error: You used one of -sl, -sd, -sa, -sp, -si or -ae but did not enable plotting with -ep") sys.exit(1) - elif enable_plotting and not (save_layout or save_deskewed or save_all or save_images or allow_enhancement): - print("Error: You used -ep to enable plotting but set none of -sl, -sd, -sa, -si or -ae") + elif enable_plotting and not (save_layout or save_deskewed or save_all or save_page or save_images or allow_enhancement): + print("Error: You used -ep to enable plotting but set none of -sl, -sd, -sa, -sp, -si or -ae") sys.exit(1) eynollah = Eynollah( image_filename=image, @@ -159,6 +166,7 @@ def main( dir_of_layout=save_layout, dir_of_deskewed=save_deskewed, dir_of_all=save_all, + dir_save_page=save_page, enable_plotting=enable_plotting, allow_enhancement=allow_enhancement, curved_line=curved_line, diff --git a/qurator/eynollah/eynollah.py b/qurator/eynollah/eynollah.py index 8957248..e56009b 100644 --- a/qurator/eynollah/eynollah.py +++ b/qurator/eynollah/eynollah.py @@ -96,6 +96,7 @@ class Eynollah: dir_of_layout=None, dir_of_deskewed=None, dir_of_all=None, + dir_save_page=None, enable_plotting=False, allow_enhancement=False, curved_line=False, @@ -121,6 +122,7 @@ class Eynollah: self.dir_out = dir_out self.dir_in = dir_in self.dir_of_all = dir_of_all + self.dir_save_page = dir_save_page self.dir_of_deskewed = dir_of_deskewed self.dir_of_deskewed = dir_of_deskewed self.dir_of_cropped_images=dir_of_cropped_images @@ -140,6 +142,7 @@ class Eynollah: self.plotter = None if not enable_plotting else EynollahPlotter( dir_out=self.dir_out, dir_of_all=dir_of_all, + dir_save_page=dir_save_page, dir_of_deskewed=dir_of_deskewed, dir_of_cropped_images=dir_of_cropped_images, dir_of_layout=dir_of_layout, @@ -219,6 +222,7 @@ class Eynollah: self.plotter = None if not self.enable_plotting else EynollahPlotter( dir_out=self.dir_out, dir_of_all=self.dir_of_all, + dir_save_page=self.dir_save_page, dir_of_deskewed=self.dir_of_deskewed, dir_of_cropped_images=self.dir_of_cropped_images, dir_of_layout=self.dir_of_layout, diff --git a/qurator/eynollah/plot.py b/qurator/eynollah/plot.py index ec4e290..b01fc04 100644 --- a/qurator/eynollah/plot.py +++ b/qurator/eynollah/plot.py @@ -19,6 +19,7 @@ class EynollahPlotter(): *, dir_out, dir_of_all, + dir_save_page, dir_of_deskewed, dir_of_layout, dir_of_cropped_images, @@ -29,6 +30,7 @@ class EynollahPlotter(): ): self.dir_out = dir_out self.dir_of_all = dir_of_all + self.dir_save_page = dir_save_page self.dir_of_layout = dir_of_layout self.dir_of_cropped_images = dir_of_cropped_images self.dir_of_deskewed = dir_of_deskewed @@ -127,6 +129,8 @@ class EynollahPlotter(): def save_page_image(self, image_page): if self.dir_of_all is not None: cv2.imwrite(os.path.join(self.dir_of_all, self.image_filename_stem + "_page.png"), image_page) + if self.dir_save_page is not None: + cv2.imwrite(os.path.join(self.dir_save_page, self.image_filename_stem + "_page.png"), image_page) def save_enhanced_image(self, img_res): cv2.imwrite(os.path.join(self.dir_out, self.image_filename_stem + "_enhanced.png"), img_res)