leaf_focus/ocr/recognise/component.py
def recognise_text(
        self,
        image_file: Path,
        annotation_file: Path,
        predictions_file: Path,
    ) -> None:
        """Recognise the text in an image and save the text and image annotations."""

        if not image_file:
            raise ValueError("Must supply image file.")
        if not annotation_file:
            raise ValueError("Must supply annotation file.")
        if not predictions_file:
            raise ValueError("Must supply predictions file.")
        if not image_file.exists():
            raise FileNotFoundError(f"Image file does not exist '{image_file}'.")

        if annotation_file.exists() and predictions_file.exists():
            self._log_debug(f"OCR output already exists for '{image_file}'.")
            return

        self._log_info(f"Running OCR on '{image_file}'.")

        # read in the image
        import keras_ocr

        images = [
            keras_ocr.tools.read(str(image_file)),
        ]

        # Each list of predictions in prediction_groups is a list of
        # (word, box) tuples.
        prediction_groups = self._pipeline.recognize(images)

        # Plot the predictions
        for image, predictions in zip(images, prediction_groups):
            self.save_figure(annotation_file, image, predictions)
            items = self.convert_predictions(predictions)
            self.save_items(predictions_file, items)
Recognise the text in an image and save the text and image annotations.
Recognise the text in an image and save the text and image annotations.
Recognise the text in an image and save the text and image annotations .
def recognise_text(
        self,
        image_file: Path,
        annotation_file: Path,
        predictions_file: Path,
    ) -> None:
        if not image_file:
            raise ValueError("Must supply image file.")
        if not annotation_file:
            raise ValueError("Must supply annotation file.")
        if not predictions_file:
            raise ValueError("Must supply predictions file.")
        if not image_file.exists():
            raise FileNotFoundError(f"Image file does not exist '{image_file}'.")
        if annotation_file.exists() and predictions_file.exists():
            self._log_debug(f"OCR output already exists for '{image_file}'.")
            return
        self._log_info(f"Running OCR on '{image_file}'.")
        import keras_ocr
        images = [
            keras_ocr.tools.read(str(image_file)),
        ]
        prediction_groups = self._pipeline.recognize(images)
        for image, predictions in zip(images, prediction_groups):
            self.save_figure(annotation_file, image, predictions)
            items = self.convert_predictions(predictions)
            self.save_items(predictions_file, items)
def recognise_text ( self , image_file : Path , annotation_file : Path , predictions_file : Path , ) -> None : if not image_file : raise ValueError ( "Must supply image file." ) if not annotation_file : raise ValueError ( "Must supply annotation file." ) if not predictions_file : raise ValueError ( "Must supply predictions file." ) if not image_file . exists ( ) : raise FileNotFoundError ( f"Image file does not exist '{image_file}'." ) if annotation_file . exists ( ) and predictions_file . exists ( ) : self . _log_debug ( f"OCR output already exists for '{image_file}'." ) return self . _log_info ( f"Running OCR on '{image_file}'." ) import keras_ocr images = [ keras_ocr . tools . read ( str ( image_file ) ) , ] prediction_groups = self . _pipeline . recognize ( images ) for image , predictions in zip ( images , prediction_groups ) : self . save_figure ( annotation_file , image , predictions ) items = self . convert_predictions ( predictions ) self . save_items ( predictions_file , items )
Recognise the text in an image and save the text and image annotations.
Recognise the text in an image and save the text and image annotations .
"""Recognise the text in an image and save the text and image annotations.""" # read in the image # Each list of predictions in prediction_groups is a list of # (word, box) tuples. # Plot the predictions
self
image_file
Path
annotation_file
Path
predictions_file
Path