How xavctn/img2table works
Project type and purpose
• This is a Python library (“img2table”) for detecting and extracting tables from images and PDF files using OpenCV‐based processing, with optional OCR integration. It is *not* a deployed application but rather a reusable package offering:
• Document ingestion (Image, PDF)
• Table detection (bordered & borderless pipelines)
• OCR abstraction layer to plug in various engines
• Data modeling of extracted tables
• Export to pandas DataFrame, HTML, or XLSX
Component relationships & data flow
1. Input (user script or notebook) feeds a source path/bytes →
2. Document Ingestion: Image or PDF class reads file, corrects rotation, produces one or multiple page images →
3. Table Detection Pipeline:
• Bordered detection sub‐pipeline runs edge/contour analysis to find tables →
• Borderless detection uses layout and whitespace analysis →
4. OCR Processing (optional): For each cell bbox, the chosen OCRInstance (strategy pattern) is invoked to extract text. If native PDF text available, skip OCR →
5. Data Modeling: Instantiate TableCell, Row, Table objects; collect them into ExtractedTable, compute metrics →
6. Export: Return a list/dict of ExtractedTable objects; user can call .df, .html, or .to_xlsx() to persist results.
Architectural patterns & principles
• Strategy Pattern for interchangeable OCR backends
• Pipeline / Chain of Responsibility for table processing (bordered → borderless → text)
• Factory‐like selection for Document type (Image vs PDF)
• Clear separation of concerns: ingestion, detection, OCR, modeling, export
Detail level
• Drill down each major pipeline into sub‐steps only if it clarifies flow (e.g., border detection → cell clustering → table creation).
• Config points (e.g., min_confidence, implicit_rows, detect_rotation).