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.0.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.0-py3-none-any.whl
(5.0 MB
view details)
File details
Details for the file ocra-0.2.0.tar.gz.
File metadata
- Download URL: ocra-0.2.0.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 |
4ee87c42b0ca6960db3489c2aed32331dc21f88062dfd18b8d04529080d287f1
|
|
| MD5 |
0f79ed4da7cb6b7c47c3c7309b3557be
|
|
| BLAKE2b-256 |
aa2c4396ec562123f095ef9de55aac4f7f89940e59518f8239808af163724714
|
File details
Details for the file ocra-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ocra-0.2.0-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 |
65aaf7009cbf05f68b60e67f8ad159d7d96c4ada6493c6ec4b761a674e06ad00
|
|
| MD5 |
76776dfb3b44a803d1612ef12d5d45f7
|
|
| BLAKE2b-256 |
705a93986826452bd32b062d31a2eee80d92468a95c954ffa214a037bf6e7fa4
|