Metadata-Version: 2.4
Name: ocra
Version: 0.2.0
Summary: ocra
Author: sherstpasha
License: MIT
Project-URL: Homepage, https://github.com/sherstpasha/Ocra
Project-URL: Repository, https://github.com/sherstpasha/Ocra
Project-URL: Issues, https://github.com/sherstpasha/Ocra/issues
Keywords: computer-vision,image-processing,orientation,rotation,onnx,pytorch
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy<3,>=1.21
Requires-Dist: Pillow>=8.0.0
Requires-Dist: tqdm>=4.65
Requires-Dist: timm>=0.9.16
Requires-Dist: opencv-python>=4.5.0
Requires-Dist: scikit-learn>=1.0.0
Provides-Extra: gpu
Requires-Dist: onnxruntime-gpu>=1.16.0; extra == "gpu"
Provides-Extra: cpu
Requires-Dist: onnxruntime>=1.16.0; extra == "cpu"

# ocra

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

Два основных инструмента:
- **`OrientationPredictor`** — определение ориентации (вертикальная/горизонтальная)
- **`HandwrittenPredictor`** — классификация типа текста (рукописный/печатный)

## Установка

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

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

---

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

```python
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](./explaing_orient.py.png)

```python
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
Классифицирует тип текста на изображении: рукописный или печатный.

```python
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']}")
```
