How shiv1810/bill-scanner-ocr works
Main Components Identification
• Frontend: Represented by the “frontend” directory with index.html, script.js, and styles.css. This part handles user interactions such as file uploads and displays results.
• Backend (Flask Application): The “backend/app.py” file acts as the core API server. Within this component, outline the following:
• API Endpoints: /upload-invoice, /confirm-invoice, and /debug-info.
• Image Preprocessing Pipeline: A sequential process including initial processing (upscaling, deskewing), enhancement (grayscale, CLAHE, thresholding), and document-specific operations (different handling for handwritten vs. printed documents).
• OCR Processing: Integration with Tesseract to convert processed images into text.
• PDF Processing: Integration with pdf2image to convert PDF invoices to images.
• Database: As described in the README, a MySQL database is used to store the extracted invoice data. Although not seen in the file tree, it is a crucial external component.
• Debug/Monitoring Modules: Note that the application generates and saves debug images and logs (even if the folder isn’t explicit in the file tree, mention that this functionality is built into the processing pipeline).
Relationships and Interactions
• The Frontend sends HTTP requests (via the API endpoints) to the Backend to upload invoices.
• The Backend processes the file by passing it sequentially through the preprocessing pipeline and then performs OCR.
• Once data is extracted, it may either be returned to the frontend (for confirmation) or saved into the MySQL database.
• There is data flow between the image processing modules and the OCR engine, with configuration differences based on the document style (printed vs. handwritten).
• Debug data flows out to log files and debug image folders to facilitate troubleshooting.
Architectural Patterns and Technologies
• MVC-like separation: Although a minimal project, the separation between frontend (view) and backend (controller/model) is clear.
• RESTful API design: The backend exposes endpoints for file upload, invoice confirmation, and debugging.
• Pipeline processing pattern: The image preprocessing uses a step-by-step pipeline to improve OCR accuracy.
• Technologies: Python with Flask for the server, OpenCV for image processing, Tesseract for OCR, pdf2image for handling PDFs, and MySQL as the persistence layer.
• “Frontend” (HTML/CSS/JS)
• “Backend – Flask API”
• “Image & PDF Processing Pipeline” (with steps like Upscaling, Deskewing, Contrast Enhancement, Thresholding, etc.)
• “OCR Engine” (Tesseract)
• “MySQL Database”
• “Debug Module/Logging”
• Rectangles for major components (frontend, backend, database)