File size: 2,119 Bytes
bd1f76d
fb59b22
ec6ad2f
 
 
bd1f76d
ec6ad2f
 
 
 
79125e3
ec6ad2f
f0dcf93
bb49e0d
ec6ad2f
 
 
 
943db10
ec6ad2f
cd9bbc0
943db10
 
 
 
ec6ad2f
 
 
 
 
 
 
f0dcf93
 
 
 
 
 
cd9bbc0
bb49e0d
f0dcf93
 
 
 
bb49e0d
0bb457d
ec6ad2f
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# from .text_detector import TextDetector
from .config import Config, load_config
from .image_processor import ImageProcessor
from .panel_extractor import PanelData
from .panel_extractor import PanelExtractor
from .panel_segmentation import main as basic_panel_segmentation

from typing import List, Tuple
from pathlib import Path
import numpy as np
from .border_panel_extractor import BorderPanelExtractor
import shutil
from . import utils
import traceback

class ComicPanelExtractor:
    """Main class that orchestrates the comic panel extraction process."""
    
    def __init__(self, config: Config, reset: bool = True):
        self.config = config
        self.reset = reset
        if reset:
            if Path(self.config.output_folder).exists():
                shutil.rmtree(self.config.output_folder)
            Path(self.config.output_folder).mkdir(exist_ok=True)
        
        self.image_processor = ImageProcessor(self.config)
        self.panel_extractor = PanelExtractor(self.config)
    
    def extract_panels_from_comic(self) -> Tuple[List[np.ndarray], List[PanelData]]:
        """Complete pipeline to extract panels from a comic image."""
        print(f"Starting panel extraction for: {self.config.input_path}")
        try:
            # Get original image dimensions
            from PIL import Image
            with Image.open(self.config.input_path) as original_image:
                original_width, original_height = original_image.size
            from .llm_panel_extractor import extract_panel_via_llm
            all_path, detected_boxes, all_processed_boxes = extract_panel_via_llm(self.config.input_path, self.config, self.reset)
            print("LLM Done.")
            if utils.box_covered_ratio(all_processed_boxes, (original_width, original_height)) < 0.95:
                print("LLM failed.")
            return None, None, all_path
        except Exception as e:
            print(f'{str(e)} {traceback.format_exc()}')
            raise
    
    def cleanup(self):
        """Clean up temporary files if needed."""
        # Add cleanup logic here if needed
        pass