leaf_focus/ocr/recognise/item.py
def save(cls, path: Path, items: List["Item"]):
        """Save found text items to a file."""
        logger = logging.getLogger(cls.__name__)
        logger.debug(f"Saving {len(items)} OCR items to '{path}'.")

        fields = [
            "text",
            "line_number",
            "line_order",
            "top_left_x",
            "top_left_y",
            "top_right_x",
            "top_right_y",
            "bottom_right_x",
            "bottom_right_y",
            "bottom_left_x",
            "bottom_left_y",
        ]
        with open(path, "wt", newline="", encoding="utf8") as f:
            writer = csv.DictWriter(f, fields)
            writer.writeheader()
            sorted_items = sorted(
                items, key=lambda i: (i.line_number or 0, i.line_order or 0)
            )
            writer.writerows([dataclasses.asdict(i) for i in sorted_items])

        logger.debug(f"Saved OCR items to '{path}'.")
Save found text items to a file.
Save found text items to a file.
Save found text items to a file .
def save(cls, path: Path, items: List["Item"]):
        logger = logging.getLogger(cls.__name__)
        logger.debug(f"Saving {len(items)} OCR items to '{path}'.")
        fields = [
            "text",
            "line_number",
            "line_order",
            "top_left_x",
            "top_left_y",
            "top_right_x",
            "top_right_y",
            "bottom_right_x",
            "bottom_right_y",
            "bottom_left_x",
            "bottom_left_y",
        ]
        with open(path, "wt", newline="", encoding="utf8") as f:
            writer = csv.DictWriter(f, fields)
            writer.writeheader()
            sorted_items = sorted(
                items, key=lambda i: (i.line_number or 0, i.line_order or 0)
            )
            writer.writerows([dataclasses.asdict(i) for i in sorted_items])
        logger.debug(f"Saved OCR items to '{path}'.")
def save ( cls , path : Path , items : List [ "Item" ] ) : logger = logging . getLogger ( cls . __name__ ) logger . debug ( f"Saving {len(items)} OCR items to '{path}'." ) fields = [ "text" , "line_number" , "line_order" , "top_left_x" , "top_left_y" , "top_right_x" , "top_right_y" , "bottom_right_x" , "bottom_right_y" , "bottom_left_x" , "bottom_left_y" , ] with open ( path , "wt" , newline = "" , encoding = "utf8" ) as f : writer = csv . DictWriter ( f , fields ) writer . writeheader ( ) sorted_items = sorted ( items , key = lambda i : ( i . line_number or 0 , i . line_order or 0 ) ) writer . writerows ( [ dataclasses . asdict ( i ) for i in sorted_items ] ) logger . debug ( f"Saved OCR items to '{path}'." )
Save found text items to a file.
Save found text items to a file .
"""Save found text items to a file."""
cls
path
Path
items
List["Item"]