Metadata-Version: 2.4
Name: dinkit
Version: 1.3.3
Summary: 手写汉字识别库 (Digital Ink Kit)
Author: liutingchao
Author-email: liutingchao@hotmail.com
License: MIT
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pywin32; platform_system == "Windows"
Dynamic: license-file

# dinkit

> Digital Ink Kit — 轻量级手写汉字识别库，纯 C 实现，毫秒级响应。

[PyPI version](https://pypi.org/project/dinkit/)
[Python](https://pypi.org/project/dinkit/)
[Platform](https://pypi.org/project/dinkit/)

## 安装

```bash
pip install dinkit
```

支持 Python 3.9+，覆盖 macOS (Apple Silicon)、Linux (x86_64)、Windows (x86_64)。

## 快速开始

### 单次识别

```python
from dinkit import recognize

strokes = [
    [[312, 211], [312, 215], [316, 231], ...],  # 第一笔
    [[382, 363], [401, 358], [420, 349], ...],  # 第二笔
]

result = recognize(strokes)
print(result)
# {'我': 3049, '找': 3784, '戌': 4144, ...}
```

### 连续识别

多次调用时用 `Recognizer` 复用引擎实例，避免重复初始化：

```python
from dinkit import Recognizer

with Recognizer() as reco:
    for strokes in batch:
        result = reco.recognize(strokes)
        print(result)
```

## 笔迹格式

```python
strokes: List[List[Tuple[int, int]]]
```

- 外层列表：一笔一画
- 内层列表：该笔包含的 `[x, y]` 坐标点序列

## API 参考

### `recognize(strokes, top_k=10) -> Dict[str, int]`

一次性调用，适合零散识别场景。


| 参数        | 类型                            | 说明           |
| --------- | ----------------------------- | ------------ |
| `strokes` | `List[List[Tuple[int, int]]]` | 笔迹坐标         |
| `top_k`   | `int`                         | 返回候选数量，默认 10 |


返回 `{汉字: 置信度}` 字典，置信度越低越好（本质是匹配距离）。

### `Recognizer` (类)

可复用的识别器，适合批量识别。

- `recognize(strokes, top_k=10)` — 识别笔迹，参数同上
- 支持 `with Recognizer() as reco:` 上下文管理器，自动释放资源

## 训练工具

从笔迹数据训练自定义识别模型，详见 [tools/train/README.md](tools/train/README.md)。

```bash
cmake .. -DBUILD_TRAIN_TOOL=ON && cmake --build . --target dinkit_train
python tools/train/make_charset.py 守卫汉字战场 -o data/charset
python tools/train/convert_track.py tools/train/examples/sample_我.json -o data/train/sample.trk
./build/tools/train/dinkit_train data/charset data/train data/test build/train_work data/output
```

## 许可证

MIT
