Skip to main content

ocra

ocra — Python-библиотека для анализа изображений текста (сканы, вырезки и т.п.).

Два основных инструмента:

  • OrientationPredictor — определение ориентации (вертикальная/горизонтальная)
  • HandwrittenPredictor — классификация типа текста (рукописный/печатный)

Установка

# С CPU поддержкой
pip install ocra[cpu] 

# С GPU поддержкой (требует CUDA + cuDNN)
pip install ocra[gpu]

Быстрый старт

from src.ocra.orientation import OrientationPredictor
from src.ocra.ishandwritten import HandwrittenPredictor

def main():
    # Инициализация
    orient_pred = OrientationPredictor(verbose=0)
    text_pred = HandwrittenPredictor(verbose=False)
    
    image = "examples/hrk_463.png"
    
    # Определение ориентации
    orient_res = orient_pred.predict_single(image)
    orientation = "VERT" if orient_res['pred_class'] == 1 else "HORZ"
    
    # Определение типа текста
    text_res = text_pred.predict_single(image)
    text_type = text_res['prediction']  # 'handwritten' или 'printed'
    
    print(f"Ориентация: {orientation} ({orient_res['confidence']:.3f})")
    print(f"Тип текста: {text_type} ({text_res['confidence']:.3f})")

if __name__ == "__main__":
    main()

Пример вывода:

Ориентация: HORZ (1.000)
Тип текста: handwritten (0.982)

OrientationPredictor

Определяет ориентацию изображения как горизонтальную (HORZ) или вертикальную (VERT).

Объяснение OrientationPredictor

from src.ocra.orientation import OrientationPredictor

predictor = OrientationPredictor()
result = predictor.predict_single("examples/hrk_463.png")

print(f"Класс: {result['pred_class']}")  # 0=HORZ, 1=VERT
print(f"Предсказание: {result['prediction']}")  # 'horizontal' или 'vertical'
print(f"Уверенность: {result['confidence']:.4f}")

HandwrittenPredictor

Классифицирует тип текста на изображении: рукописный или печатный.

from src.ocra.ishandwritten import HandwrittenPredictor

predictor = HandwrittenPredictor()
result = predictor.predict_single("examples/hrk_463.png")

print(f"Класс: {result['pred_class']}")     # 0=printed, 1=handwritten
print(f"Предсказание: {result['prediction']}")  # 'handwritten' или 'printed'
print(f"Уверенность: {result['confidence']:.4f}")
print(f"Высокая уверенность: {result['high_confidence']}")

Release files for ocra 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ocra 0.2.1
File Size Uploaded
ocra-0.2.1.tar.gz 5.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for ocra 0.2.1
File Interpreter ABI Platform
ocra-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 MB

Release files / ocra-0.2.1.tar.gz

Download URL ocra-0.2.1.tar.gz
Size 5.0 MB
Tags Source
SHA-256 checksum
How to use checksums
c2d71de0b5950b9711dce2426e5b9dc859eaa5cdc3c99a6234245765fd658d0a
BLAKE2b-256 checksum
How to use checksums
31f99a932ec23fedd0522ac64a6d8ed4b3b84604ad84c0de273088338844773a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.8

Release files / ocra-0.2.1-py3-none-any.whl

Download URL ocra-0.2.1-py3-none-any.whl
Size 5.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
84d6c74daa102ae2ccf7924a7b9e93d874c40abb5e9449838f9f09aab77cf39e
BLAKE2b-256 checksum
How to use checksums
fd844488bcd182c36d0cccb3f18d7f0c5f4ac9926761817632fd4da0e53beecd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page