leaf_focus/ocr/recognise/item.py
def load(cls, path: Path):
        """Load found text items from a file."""
        logger = logging.getLogger(cls.__name__)
        logger.debug(f"Loading OCR items from '{path}'.")
        count = 0

        with open(path, "rt", encoding="utf8") as f:
            reader = csv.DictReader(f)
            for row in reader:
                line_number = row.get("line_number", "").strip()
                line_number = int(line_number) if line_number != "" else None

                line_order = row.get("line_order", "").strip()
                line_order = int(line_order) if line_order != "" else None

                count += 1

                yield Item(
                    text=row["text"],
                    line_number=line_number,
                    line_order=line_order,
                    top_left_x=float(row["top_left_x"]),
                    top_left_y=float(row["top_left_y"]),
                    top_right_x=float(row["top_right_x"]),
                    top_right_y=float(row["top_right_y"]),
                    bottom_right_x=float(row["bottom_right_x"]),
                    bottom_right_y=float(row["bottom_right_y"]),
                    bottom_left_x=float(row["bottom_left_x"]),
                    bottom_left_y=float(row["bottom_left_y"]),
                )

        logger.debug(f"Loaded {count} OCR items from '{path}'.")
Load found text items from a file.
Load found text items from a file.
Load found text items from a file .
def load(cls, path: Path):
        logger = logging.getLogger(cls.__name__)
        logger.debug(f"Loading OCR items from '{path}'.")
        count = 0
        with open(path, "rt", encoding="utf8") as f:
            reader = csv.DictReader(f)
            for row in reader:
                line_number = row.get("line_number", "").strip()
                line_number = int(line_number) if line_number != "" else None
                line_order = row.get("line_order", "").strip()
                line_order = int(line_order) if line_order != "" else None
                count += 1
                yield Item(
                    text=row["text"],
                    line_number=line_number,
                    line_order=line_order,
                    top_left_x=float(row["top_left_x"]),
                    top_left_y=float(row["top_left_y"]),
                    top_right_x=float(row["top_right_x"]),
                    top_right_y=float(row["top_right_y"]),
                    bottom_right_x=float(row["bottom_right_x"]),
                    bottom_right_y=float(row["bottom_right_y"]),
                    bottom_left_x=float(row["bottom_left_x"]),
                    bottom_left_y=float(row["bottom_left_y"]),
                )
        logger.debug(f"Loaded {count} OCR items from '{path}'.")
def load ( cls , path : Path ) : logger = logging . getLogger ( cls . __name__ ) logger . debug ( f"Loading OCR items from '{path}'." ) count = 0 with open ( path , "rt" , encoding = "utf8" ) as f : reader = csv . DictReader ( f ) for row in reader : line_number = row . get ( "line_number" , "" ) . strip ( ) line_number = int ( line_number ) if line_number != "" else None line_order = row . get ( "line_order" , "" ) . strip ( ) line_order = int ( line_order ) if line_order != "" else None count += 1 yield Item ( text = row [ "text" ] , line_number = line_number , line_order = line_order , top_left_x = float ( row [ "top_left_x" ] ) , top_left_y = float ( row [ "top_left_y" ] ) , top_right_x = float ( row [ "top_right_x" ] ) , top_right_y = float ( row [ "top_right_y" ] ) , bottom_right_x = float ( row [ "bottom_right_x" ] ) , bottom_right_y = float ( row [ "bottom_right_y" ] ) , bottom_left_x = float ( row [ "bottom_left_x" ] ) , bottom_left_y = float ( row [ "bottom_left_y" ] ) , ) logger . debug ( f"Loaded {count} OCR items from '{path}'." )
Load found text items from a file.
Load found text items from a file .
"""Load found text items from a file."""
cls
path
Path