Parsetext is open source Optical Character Recognition(OCR) application for recognizing and processing Persian text. It provides precise text extraction, finely tuned to the unique characteristics of the Persian language.
ParseText, in this version, focuses on recognizing word-level data from documented sources. This marks the beginning of a long journey toward building a comprehensive OCR solution for Persian text.
This project is in its early stages, but there are exciting plans to expand and enhance its capabilities. The roadmap includes:
- Text Detection: Implementing, fine-tuning, or integrating existing text detectors to accurately locate text regions in images before recognition.
- Outdoor Text Recognition: Enhancing the OCR model to detect and recognize outdoor texts such as traffic signs, market signs, and other environmental text.
- Sentence and Paragraph Recognition: Moving beyond word-level recognition to process complete textual structures. Handling Complex Ligatures and Diacritics: Improved recognition of intricate aspects of Persian script.
- Real-Time OCR: Developing real-time OCR capabilities for dynamic image sources.
- NLP Integration: Incorporating context-aware text processing for semantic analysis.
Stay tuned as ParseText evolves to meet these goals and more!
- Clone the repository:
git clone https://github.com/arman-hm/ParseText
-
Install dependencies:
Requirments:
- albumentations==2.0.1
- Levenshtein==0.26.1
- matplotlib==3.10.0
- numpy==2.2.2
- pandas==2.2.3
- pillow==11.1.0
- torch==2.5.1
- tqdm==4.67.1
pip install -r requirements.txt
-
Download pretrained weights:
Download pretrained model from here or:
pip install gdown
gdown https://drive.google.com/uc?id=1xEsHmCrvpDtQKeNT8KF9VExBv2GjSyNR
To recognize text from an image:
- Testing model:
python test.py --imgdir <folder of images> --CRNN <path to model> --outputdir <dir to save result>
- Use it in code:
import text_recognizer
from PIL import Image
with open("char_to_index.json", 'r', encoding="utf-8") as file:
data = json.load(file)
char2index = data["char_to_index"]
tr = text_recognizer.TextRecognizer(model_path= "path_to_pretrained_model", char_index=char2index
, device="cuda_or_cpu")
# Feed list of PIL images in list to model
img = Image.open("file_path")
result = tr.inference(images =[img])To train the model on a custom dataset:
python train.py --traindf <dir to train df> --testdf <dir to test df>
For detailed information about the training options, check the docstrings in train.py. These options allow you to:
- Customize the learning rate, batch size, and optimizer settings.
- Select or switch between different architectures or loss functions.
- Specify checkpoints, evaluation frequency, and logging preferences
- Enable data augmentation and preprocessing techniques.
With these configurations, you can adapt the training process to meet your project’s specific requirements.
Contributions are welcome!
This project is licensed under the MIT License.
MIT License
Copyright (c) 2025 Arman-hm
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.