ocra
Project description
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).
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']}")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ocra-0.2.1.tar.gz
(5.0 MB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
ocra-0.2.1-py3-none-any.whl
(5.0 MB
view details)
File details
Details for the file ocra-0.2.1.tar.gz.
File metadata
- Download URL: ocra-0.2.1.tar.gz
- Upload date:
- Size: 5.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2d71de0b5950b9711dce2426e5b9dc859eaa5cdc3c99a6234245765fd658d0a
|
|
| MD5 |
61ff49e4e1d66798f269a74dd5805aa9
|
|
| BLAKE2b-256 |
31f99a932ec23fedd0522ac64a6d8ed4b3b84604ad84c0de273088338844773a
|
File details
Details for the file ocra-0.2.1-py3-none-any.whl.
File metadata
- Download URL: ocra-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84d6c74daa102ae2ccf7924a7b9e93d874c40abb5e9449838f9f09aab77cf39e
|
|
| MD5 |
c84e4e979c1e656152ac462d171ad38a
|
|
| BLAKE2b-256 |
fd844488bcd182c36d0cccb3f18d7f0c5f4ac9926761817632fd4da0e53beecd
|