Posts

Showing posts from September, 2024

Extracting Tables and Text from Images Using Python

Image
In this blog, we'll explore a complete Python solution that detects and extracts tables and text from images using libraries like Transformers, OpenCV, PaddleOCR, and easyOCR. This step-by-step breakdown includes code to detect tables, extract content from individual table cells, and retrieve any remaining text in the image. Overview When working with scanned documents, such as invoices or forms, it is essential to accurately extract both structured information (like tables) and unstructured text. The approach we’ll explore uses Microsoft's pretrained object detection model to locate tables and OCR techniques to extract the text from both table cells and the rest of the image. Steps: 1. This code first detects table using microsoft's model. and save that image which contains detected table only  2. After that, from the detected table , we make a seperate image for each cell.  3. Then we read text from the image of each cell  4. Now, to read the extra texts except for the ...

Extract Image from PDF

Image
 Extract Images from PDFs Using PyMuPDF in Python I/p:- PDF- O/p - Images - Why PyMuPDF? PyMuPDF (fitz) is a powerful library for PDF processing. It allows easy access to various elements within a PDF, including text, images, and metadata. It’s particularly well-suited for tasks that involve reading and manipulating PDFs. Prerequisites pip install pymupdf Code Steps :  1. Importing Required Libraries import fitz  # PyMuPDF import os 2. Function to Extract Images from a PDF def extract_images_from_pdf(pdf_path, output_folder):     # Open the PDF file     pdf_document = fitz.open(pdf_path)     filename = os.path.basename(pdf_path).split('.')[0]          # Create the output directory if it doesn't exist     if not os.path.exists(output_folder):         os.makedirs(output_folder)     # Loop through each page     for page_number in range(len(pdf_document)):     ...