This project focuses on extracting and processing text from Egyptian and Marrocan ID cards, specifically targeting Arabic OCR (Optical Character Recognition). The system uses deep learning models to detect and segment ID cards, and OCR technology to recognize text within the segments.
- ID Detection: Identifies whether the uploaded image contains an ID card.
- Segmentation: Segments the ID card into different regions (e.g., name, number, etc.).
- Text Extraction: Uses OCR to extract text from each segmented region.
- Custom Text Processing: Cleans and filters the extracted text to enhance readability.
- Ordering of Text Segments: Processes text segments in a specific, user-defined order.
To run this project, you'll need to have Python 3.8 or higher installed. Additionally, you will need to install the following dependencies:
- FastAPI: For creating the API.
- Pillow: For image processing.
- PyTesseract: For OCR functionality.
- NLTK: For text processing.
- Tesseract-OCR: The OCR engine.
You can install the required Python libraries using pip:
pip install fastapi uvicorn pillow pytesseract nltk
Tesseract-OCR needs to be installed separately. You can download and install it from Tesseract's official repository.
-
Models:
classification.pt
: Model for detecting ID cards.segmentation.pt
: Model for segmenting the ID card into regions.
-
Tesseract Configuration:
- Ensure that
pytesseract.pytesseract.tesseract_cmd
points to the path where Tesseract-OCR is installed.
- Ensure that
-
Start the API Server
To run the FastAPI server, execute the following command in your terminal:
uvicorn main:app --reload
This command starts the server and enables automatic reloading for development. 2. Upload an Image: You can send a POST request to the /predict/ endpoint with an image file. You can use tools like curl, Postman, or create a simple frontend to interact with the API.
The API will process the image and return the extracted text from the ID card in the specified order. The response will be in JSON format.
{
"id informations": [
"أحمد",
"محمد إبراهيم علي",
"منطقة الليدو",
"المنتزه",
"الإسكندرية",
"7542907 3658463",
"QW5613784"
]
}