Skip to content

aspose-ocr/Aspose.OCR-for-Python-via-NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PyPI PyPI GitHub

Optical Character Recognition (OCR) Python API via .NET

This is a standalone OCR API that enhances your Python applications to perform OCR on JPEG, PNG, GIF, BMP & TIFF images for extraction of English, French, Spanish & Portuguese content.

Aspose.OCR for Python via .NET not only provides the Optical Character Recognition engine but more. You can also apply Blur, Gaussian Blur, and Median filter to reduce noise before document recognition and can set the OcrEngine to ignore non-textual blocks, maintain correct text order during document text recognition & automatically correct spellings of the document text.

Directory Description
examples A collection of Python examples that help you learn the product features.

Image OCR API Features

  • Programmatically detect, identify and read characters from images.
  • Currently, it supports 140+ languages.
  • Detect and read popular font faces such as Arial, Times New Roman, Courier New, Tahoma, Calibri & Verdana.
  • Supports regular, bold and italic font styles.
  • Scan whole image or only a specific portion of the image.
  • Scan rotated images.
  • Application of various noise removal filters to assist image recognition.
  • Calculate the bounding boxes of lines, paragraphs, words.
  • Get possible choices for each recognized character.
  • Pass URI and recognize the image from it.
  • Recognize multiple images in a folder, zip archive or in the list.
  • Get result in JSON or XML format.
  • Save results in text, DOCX, PDF, XLSX, XML, JSON formats

Aspose.OCR can recognize a large number of languages and all popular writing scripts, including texts with mixed languages.

Load Images for OCR

Raster Formats: JPEG, PNG, GIF, BMP, TIFF

Platform Independence

You can use Aspose.OCR for Python via .NET to develop applications in any development environment that supports Python 3.6 and higher. The library is built on top of .NET Framework, providing cross-platform compatibility.

Get Started with Aspose.OCR for Python via .NET

Are you ready to give Aspose.OCR for Python via .NET a try? Simply execute pip install aspose-ocr-python-net to fetch the package from PyPI. If you already have Aspose.OCR for Python via .NET and want to upgrade the version, please execute pip install --upgrade aspose-ocr-python-net to get the latest version.

Quick Setup

  1. Install the package:

    pip install aspose-ocr-python-net
  2. Run examples:

    # Windows
    run.cmd
    
    # Linux/Mac
    ./run.sh

Perform OCR on PNG Image via Python Code

Task: Extract text from a single PNG image with preprocessing filters and table detection mode.

This example demonstrates basic OCR functionality with image preprocessing for recognition of rotated or tilted images with automatic correction, and optimized settings for table recognition.

import aspose.ocr as ocr

# initialize main class
api = ocr.AsposeOcr()

# set preprocessing options
filters = ocr.models.preprocessingfilters.PreprocessingFilter()
filters.add(ocr.models.preprocessingfilters.PreprocessingFilter.auto_skew())

# Create OcrInput and add images
input = ocr.OcrInput(ocr.InputType.SINGLE_IMAGE, filters)
input.add("Data/OCR/sample.png")

# set recognition options
settings = ocr.RecognitionSettings()
settings.detect_areas_mode = ocr.DetectAreasMode.TABLE
settings.threads_count = 1
settings.language = ocr.Language.ENG

# recognize
result = api.recognize(input, settings)

# print result
print(result[0].recognition_text)

Available Examples

This repository contains the following Python examples:

  • Basic Recognition:

    • recognize.py - Basic image recognition
    • recognize_line.py - Line-by-line text recognition
    • recognize_images_batch.py - Batch processing of multiple images
  • Specialized Recognition:

    • recognize_handwritten.py - Handwritten text recognition
    • recognize_table.py - Table structure recognition
    • recognize_passport.py - Passport document recognition
    • recognize_car_plate.py - License plate recognition
    • recognize_street_photo.py - Street sign recognition
  • Advanced Features:

    • recognize_with_language.py - Multi-language recognition
    • recognize_with_spell_check.py - Spell-checking during recognition
    • recognize_with_detect_areas_mode.py - Custom area detection modes
    • calculate_skew.py - Image skew calculation and correction
    • image_text_finder.py - Text location detection
  • Input Sources:

    • recognize_url.py - Recognition from URL
    • recognize_folder.py - Recognition from folder
    • recognize_archive.py - Recognition from archive files
  • Output Options:

    • recognize_and_save_result_as_file.py - Save results to various formats

Data Directory

The examples/Data/ directory contains sample images and resources for testing the examples:

  • Various image formats (PNG, JPEG, BMP, etc.)
  • Multi-language text samples
  • Handwritten text samples
  • Table structures
  • Document samples (passports, etc.)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Additional Code Examples

Extract Text from Image with Custom Settings

Task: Extract text with detailed line-by-line information including confidence scores and bounding boxes.

This example shows how to configure advanced recognition settings for better accuracy and obtain detailed recognition results with confidence scores and text positioning information. Uses DOCUMENT mode for images with complex structure and columns.

import aspose.ocr as ocr

# Initialize OCR engine
api = ocr.AsposeOcr()

# Create recognition settings
settings = ocr.RecognitionSettings()
settings.language = ocr.Language.ENG
settings.threads_count = 4
settings.detect_areas_mode = ocr.DetectAreasMode.DOCUMENT

# Recognize text from image
result = api.recognize("Data/OCR/sample.png", settings)

# Print results
for line in result[0].lines:
    print(f"Line: {line.text}")
    print(f"Confidence: {line.confidence}")
    print(f"Bounding box: {line.rect}")

Process Multiple Images with Different Languages

Task: Process multiple images containing different languages in a single batch operation.

This example demonstrates batch processing capabilities and automatic language detection for multilingual content, allowing you to process images with different languages efficiently. Uses MULTILANGUAGE mode for images with multiple languages or automatic language detection (takes longer to process).

import aspose.ocr as ocr

# Initialize OCR engine
api = ocr.AsposeOcr()

# Create input for multiple images
input = ocr.OcrInput(ocr.InputType.SINGLE_IMAGE)

# Add images with different languages
input.add("Data/OCR/english_text.png")
input.add("Data/OCR/spanish_text.png")
input.add("Data/OCR/russian_text.png")

# Create settings for multi-language recognition
settings = ocr.RecognitionSettings()
settings.language = ocr.Language.MULTILANGUAGE
settings.threads_count = 2

# Process all images
results = api.recognize(input, settings)

# Print results for each image
for i, result in enumerate(results):
    print(f"Image {i+1}:")
    print(f"Text: {result.recognition_text}")
    print(f"Language: {result.language}")
    print("---")

Save OCR Results to Different Formats

Task: Save OCR recognition results to various document formats for different use cases.

This example shows how to export OCR results to different file formats (TXT, DOCX, PDF) to integrate with various document workflows and applications.

import aspose.ocr as ocr

# Initialize OCR engine
api = ocr.AsposeOcr()

# Recognize text from image
result = api.recognize("Data/OCR/sample.png")

# Save results to different formats using SaveFormat enum
# Save as plain text
result[0].save("output.txt", ocr.SaveFormat.TEXT)

# Save as DOCX document
result[0].save("output.docx", ocr.SaveFormat.DOCX)

# Save as PDF document
result[0].save("output.pdf", ocr.SaveFormat.PDF)

print("Results saved to multiple formats successfully!")

Process PDF Documents with Advanced Save Options

Task: Extract text from PDF documents and save results to multiple formats with optimization settings.

This example demonstrates advanced PDF processing capabilities including page range selection, multiple output formats (XML, JSON, XLSX, DOCX, TXT, HTML, EPUB, RTF), and PDF optimization for better file size and performance. When input is PDF, save_pdf converts it to searchable PDF.

import aspose.ocr as ocr
import os

# Set license (if you have one)
# lic = ocr.License()
# lic.set_license("path/to/license.lic")

# Initialize OCR engine
api = ocr.AsposeOcr()

# Create input for PDF processing
input = ocr.OcrInput(ocr.InputType.PDF)

# Add PDF file with page range (pages 0-3)
file = os.path.join("Data", "pdfs", "multi_page_1.pdf")
input.add(file, 0, 3)

# Create recognition settings
settings = ocr.RecognitionSettings()
settings.detect_areas_mode = ocr.DetectAreasMode.LEAN

# Recognize PDF pages
result = api.recognize(input, settings)

# Save results with different optimization options
# Basic save formats
result.save("test.xml", ocr.SaveFormat.XML)
result.save("test.json", ocr.SaveFormat.JSON)
result.save("test.xlsx", ocr.SaveFormat.XLSX)
result.save("test.docx", ocr.SaveFormat.DOCX)
result.save("test.txt", ocr.SaveFormat.TEXT)
result.save("test.html", ocr.SaveFormat.HTML)
result.save("test.epub", ocr.SaveFormat.EPUB)
result.save("test.rtf", ocr.SaveFormat.RTF)

# Save as PDF with optimization
result.save_pdf("test.pdf", "", ocr.PdfOptimizationMode.AGGRESSIVE)

print("PDF processing completed and results saved!")

Supported Languages

Aspose.OCR for Python via .NET supports a wide range of languages and scripts:

Latin-based Languages

  • Multi-language (Extended Latin) - Supports all Latin alphabet languages with diacritics
  • English (ENG) - English alphabet
  • German (DEU) - German alphabet
  • Portuguese (POR) - Portuguese alphabet
  • Spanish (SPA) - Spanish alphabet
  • French (FRA) - French alphabet
  • Italian (ITA) - Italian alphabet
  • Czech (CES) - Czech alphabet
  • Danish (DAN) - Danish alphabet
  • Dutch (NLD) - Dutch alphabet
  • Estonian (EST) - Estonian alphabet
  • Finnish (FIN) - Finnish alphabet
  • Latvian (LAV) - Latvian alphabet
  • Lithuanian (LIT) - Lithuanian alphabet
  • Norwegian (NOR) - Norwegian alphabet
  • Polish (POL) - Polish alphabet
  • Romanian (RON) - Romanian alphabet
  • Serbo-Croatian (HBS) - Serbo-Croatian alphabet
  • Slovak (SLK) - Slovak alphabet
  • Slovene (SLV) - Slovene alphabet
  • Swedish (SWE) - Swedish alphabet
  • Hungarian (HUN) - Hungarian alphabet
  • Catalan (CAT) - Catalan alphabet
  • Afrikaans (AFR) - Afrikaans alphabet
  • Galician (GLG) - Galician alphabet
  • Albanian (ALN) - Albanian alphabet

Cyrillic-based Languages

  • Multi-language (Cyrillic) - Supports all Cyrillic alphabet languages
  • Belorussian (BEL) - Belorussian alphabet
  • Bulgarian (BUL) - Bulgarian alphabet
  • Kazakh (KAZ) - Kazakh alphabet
  • Russian (RUS) - Russian alphabet
  • Serbian (SRP) - Serbian alphabet
  • Ukrainian (UKR) - Ukrainian alphabet
  • Bosnian (BOS) - Bosnian alphabet
  • Croatian (HRV) - Croatian alphabet

Asian Languages

  • Chinese (CHI) - Universal recognition of Chinese-based languages, including mixed Chinese-English texts
  • Mandarin Chinese (CMN) - Mandarin Chinese alphabet
  • Cantonese (YUE) - Cantonese alphabet
  • Min Nan (NAN) - Min Nan alphabet
  • Hakka (HAK) - Hakka alphabet
  • Xiang (HSN) - Xiang alphabet
  • Gan (GAN) - Gan alphabet
  • Min Bei (MNP) - Min Bei alphabet
  • Min Dong (CDO) - Min Dong alphabet
  • Wu (WUU) - Changzhou alphabet

Indic Languages

  • Hindi (HIN) - Hindi alphabet
  • Marathi (MAR) - Marathi alphabet
  • Bhojpuri (BHO) - Bhojpuri alphabet
  • Maithili (MAI) - Maithili alphabet
  • Nepali (NEP) - Nepali alphabet
  • Zhuang (CCX) - Zhuang alphabet
  • Marwari (RWR) - Marwari alphabet
  • Magahi (MAG) - Magahi alphabet
  • Haryanvi (BGC) - Haryanvi alphabet
  • Chattisgarhi (HNE) - Chattisgarhi alphabet
  • Dhundari (DHD) - Dhundari alphabet
  • Kanauji (BJJ) - Kanauji alphabet
  • Mewati (WTM) - Mewati alphabet
  • Rajbanshi (RJB) - Rajbanshi alphabet
  • Garhwali (GBM) - Garhwali alphabet
  • Lamani (LMN) - Lamani alphabet
  • Kumauni (KFY) - Kumauni alphabet
  • Malvi (MUP) - Malvi alphabet
  • Mewari (MTR) - Mewari alphabet

Southeast Asian Languages

  • Indonesian (IND) - Indonesian alphabet
  • Vietnamese (VIE) - Vietnamese alphabet
  • Malay (MLY) - Malay (Melayu) alphabet
  • Tagalog (TGL) - Tagalog (Pilipino) alphabet
  • Cebuano (CEB) - Cebuano alphabet
  • Ilocano (ILO) - Ilocano alphabet
  • Hiligaynon (HIL) - Hiligaynon alphabet
  • Waray-Waray (WAR) - Waray-Waray alphabet
  • Kapampangan (PAM) - Kapampangan alphabet
  • Bikol (BCL) - Bikol alphabet
  • Minangkabau (MIN) - Minangkabau alphabet
  • Sundanese (SUN) - Sundanese (Sunda) alphabet
  • Palembang (PLM) - Palembang alphabet
  • Musi (MUI) - Musi alphabet
  • Sasak (SAS) - Sasak alphabet
  • Makassar (MAK) - Makassar (Makasar) alphabet
  • Betawi (BEW) - Betawi alphabet

African Languages

  • Hausa (HAU) - Hausa alphabet
  • Swahili (SWH) - Swahili alphabet
  • Oromo (GAX) - Oromo alphabet
  • Malagasy (BHR) - Malagasy alphabet
  • Somali (SOM) - Somali alphabet
  • Chichewa (NYA) - Chichewa (Chewa, Nyanja) alphabet
  • Rwanda (KIN) - Rwanda alphabet
  • Zulu (ZUL) - Zulu alphabet
  • Sotho (SOT) - Sotho (Southern) alphabet
  • Sotho Northern (NSO) - Sotho (Northern) alphabet
  • Tswana (TSN) - Tswana alphabet
  • Kikongo (KON) - Kikongo alphabet
  • Luo (LUO) - Luo alphabet
  • Sukuma (SUK) - Sukuma alphabet
  • Tsonga (TSO) - Tsonga alphabet
  • Bemba (BEM) - Bemba (Chibemba) alphabet
  • Nandi (KLN) - Nandi alphabet
  • Umbundu (UMB) - Umbundu alphabet
  • Shona (SNA) - Shona (Karanga) alphabet
  • Xhosa (XHO) - Xhosa alphabet
  • Konkani (KNN) - Konkani alphabet
  • Ndebele (NBL) - Ndebele alphabet
  • Yao (YAO) - Yao alphabet
  • Swati (SSW) - Swati (Swazi) alphabet
  • Gusii (GUZ) - Gusii alphabet
  • Meru (MER) - Meru alphabet
  • Wagdi (WBR) - Wagdi alphabet
  • Wolaytta (WAL) - Wolaytta alphabet
  • Dong (DOC) - Dong alphabet
  • Pangasinan (PAG) - Pangasinan alphabet
  • Makassar (MAK) - Makassar (Makasar) alphabet
  • Tumbuka (TUM) - Tumbuka alphabet
  • Serer-Sine (SRR) - Serer-Sine alphabet
  • Tonga (TOI) - Tonga alphabet
  • Muong (MTQ) - Muong alphabet
  • K'iche' (QUC) - K'iche' alphabet
  • Malvi (MUP) - Malvi alphabet
  • Mewari (MTR) - Mewari alphabet
  • Kabardian (KBD) - Kabardian alphabet
  • Luguru (RUF) - Luguru alphabet

Middle Eastern Languages

  • Arabic (ARA) - Arabic alphabet
  • Persian (PES) - Persian (Farsi) alphabet
  • Urdu (URD) - Urdu alphabet
  • Uyghur (UIG) - Uyghur alphabet
  • Azerbaijani (AZB) - Azerbaijani (Azeri) alphabet
  • Kurdish (KMR) - Kurdish (Kurmanji) alphabet
  • Turkmen (TUK) - Turkmen alphabet
  • Chechen (CHE) - Chechen alphabet
  • Dimli (DIQ) - Dimli alphabet

Other Languages

  • Turkish (TUR) - Turkish alphabet
  • Korean (KOR) - Korean alphabet
  • Japanese (JPN) - Japanese alphabet
  • Tamil (TAM) - Tamil alphabet
  • Telugu (TEL) - Telugu alphabet
  • Kannada (KAN) - Kannada alphabet
  • Mongolian (MON) - Mongolian alphabet
  • Quechua (QXA) - Quechua alphabet
  • Hmong (HMN) - Hmong alphabet
  • Yoruba (YOR) - Yoruba alphabet
  • Awadhi (AWA) - Awadhi alphabet
  • Bouyei (PCC) - Bouyei (Buyi, Giáy) alphabet
  • Pu-Xian (CPX) - Pu-Xian alphabet
  • Occitan (LNC) - Occitan alphabet
  • Low German (NDS) - Low German alphabet
  • Gilaki (GLK) - Gilaki alphabet

Universal Recognition Modes

  • Multilanguage (MULTILANGUAGE) - Automatically detects the language in the input document or image
  • Auto (AUTO) - Automatically detects the language in the input document or image
  • Universal (UNIVERSAL) - Automatically detects the language in the input document or image
  • European (EUROPEAN) - Experimental recognition of mixed Cyrillic/English texts
  • Indic (INDIC) - Universal recognition of Indic languages based on Devanagari script
  • Devanagari (DEVANAGARI) - Universal recognition of Indic languages based on Devanagari script
  • PersoArabic (PERSOARABIC) - Universal Perso-Arabic alphabet
  • Islamic (ISLAMIC) - Universal Perso-Arabic alphabet

Home | Product Page | Docs | Demos | API Reference | Examples | Blog | Search | Free Support | Temporary License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published