DSH 的本地 Windows 11 OneOCR 工具:`oneocr_recognize` 返回 OCR 文本,以及包含行/词多边形、置信度、旋转角度和手写体样式的结构化结果。
安装
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:hawkhai/win11-oneocr
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本。请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
该插件的 README 只有英文版本。
Offline OCR engine extracted from the Windows 11 Snipping Tool, with full-featured C++ CLI, reusable DLL wrapper, and Python visualization.
Based on: https://b1tg.github.io/post/win11-oneocr/
DeepSeek Harness plugin
This repository can be installed as a DeepSeek Harness plugin:
dsh plugin add github:hawkhai/win11-oneocr
It registers oneocr_recognize, a model-facing tool that accepts a local image path and returns recognized text together with OneOCR's structured line/word polygons, confidence values, image angle, and handwriting style. The tool runs locally on Windows 11; image bytes are not sent to an external OCR service.
The bundle defaults to the prebuilt bin/ocr.exe and its adjacent runtime files. Override ocrBin, timeoutMs, or maxOutputBytes in the plugin row if needed.
Features
| Feature | Description |
|---|---|
| 8-point Bounding Box | 4-corner polygon bbox for lines and words (not just axis-aligned rect) |
| Word Confidence | Per-word recognition confidence score (0.0–1.0) |
| Image Angle | Detected rotation angle of the text in the image |
| Line Style | Handwritten vs. printed text classification with confidence |
| Resize Resolution | Configurable max internal resize before OCR (performance/accuracy trade-off) |
| Resource Release | Proper cleanup via ReleaseOcrResult, ReleaseOcrPipeline, etc. |
| Unicode Path | Full Unicode file path support via _wfopen in the DLL wrapper |
| Multi-image Batch | Process multiple images in one invocation |
| Plain Text Output | --text mode for pipe-friendly output (no JSON) |
| Raw Buffer OCR | ocrImageRaw() for in-memory BGRA pixel buffers (no file I/O) |
| Visualization | Python script with confidence-colored word boxes and style labels |
Prerequisites
- Windows 11 (tested on 23H2+)
- Snipping Tool 11.2409.25.0+
Copy these 3 files from the Snipping Tool installation folder into the same directory as ocr.exe:
oneocr.dlloneocr.onemodelonnxruntime.dll
Find the Snipping Tool folder:
Get-AppxPackage Microsoft.ScreenSketch | Select-Object -ExpandProperty InstallLocation
Example: C:\Program Files\WindowsApps\Microsoft.ScreenSketch_11.2409.25.0_x64__8wekyb3d8bbwe\SnippingTool
CLI Usage (ocr.exe)
ocr.exe <image1.png> [image2.jpg ...] [options]
Options
| Option | Description |
|---|---|
--text, -t |
Output plain text only (no JSON) |
--output, -o <file> |
Write JSON to specified file (default: <image>.json) |
--max-lines <n> |
Max recognition lines, 1–1000 (default 1000) |
--resize <WxH> |
Max internal resize resolution (e.g. 1152x768) |
--quiet, -q |
Suppress progress messages |
--help, -h |
Show help |
Examples
# Single image → JSON
ocr.exe screenshot.png
# Plain text output (pipe to file)
ocr.exe screenshot.png --text > result.txt
# Batch process
ocr.exe img1.png img2.jpg img3.bmp
# Custom options
ocr.exe photo.jpg --max-lines 50 --resize 800x600 -o result.json
JSON Output Format
{
"file": "test.png",
"image": { "width": 771, "height": 479, "step": 3084 },
"image_angle": 0.0643,
"line_count": 2,
"lines": [
{
"index": 0,
"text": "Hello World",
"bounding_box": [
13.0, 38.0, 458.0, 38.0,
458.0, 77.0, 13.0, 76.0
],
"style": { "type": "printed", "confidence": 0.035 },
"word_count": 2,
"words": [
{
"index": 0,
"text": "Hello",
"bounding_box": [
14.35, 39.70, 140.35, 41.31,
139.93, 73.42, 13.78, 74.09
],
"confidence": 0.987
}
]
}
]
}
DLL Wrapper (oneocr_wrapper.dll)
A reusable C DLL wrapper with 3 main APIs:
| Function | Description |
|---|---|
initModel(model_dir) |
Load DLL + model, initialize pipeline |
ocrImage(image_path, json, alloc) |
OCR an image file → JSON string |
ocrImageEx(image_path, json, alloc, max_lines, resize_w, resize_h) |
OCR with configurable options |
ocrImageRaw(pixel_data, w, h, step, json, alloc) |
OCR on raw BGRA pixel buffer |
releaseModel() |
Clean up all resources |
C++ Header-Only Usage (oneocr.h)
#include "oneocr.h"
OneOcr ocr; // loads oneocr_wrapper.dll
ocr.initModel(L"."); // directory with oneocr.dll + .onemodel
std::string json;
ocr.ocrImage(L"test.png", json); // basic OCR
ocr.ocrImageEx(L"test.png", json, 50); // max 50 lines
ocr.ocrImageRaw(bgra_ptr, w, h, json); // raw buffer OCR
Visualization (visualize.py)
python visualize.py <image_path> <json_path> [output_path]
Features:
- 8-point polygon bounding boxes (lines in red, words colored by confidence)
- Confidence score labels below each word
- Handwritten lines highlighted in orange, printed in red
- Image angle and line count overlay
Build
Requires: MSVC (Visual Studio), json.hpp (nlohmann/json), stb_image.h.
# Build CLI
cl /EHsc /O2 ocr.cpp /Fe:ocr.exe
# Build wrapper DLL
cl /EHsc /O2 /LD oneocr_wrapper.cpp /Fe:oneocr_wrapper.dll
# Build test
cl /EHsc /O2 oneocr_test.cpp /Fe:oneocr_test.exe
Other Implementations
| Directory | Language | Description |
|---|---|---|
oneocr/ |
Python | PyPI package with PIL/cv2 input, FastAPI web server |
oneocr-rs/ |
Rust | crates.io library with image crate, serde JSON |
oneocr-cli/ |
Rust | Minimal CLI, plain text output |
win11_oneocr_py/ |
Python | Basic ctypes script (original Python port) |
Credits
- b1tg - Original reverse engineering and C++ implementation
- AuroraWright/oneocr - Python package with web server
- wangfu91/oneocr-rs - Rust binding with full feature coverage
- Cecilia-pj/win11_oneocr_py - Original Python port
License
MIT
链接
同类插件
liustack/modlens★ 3005
为纯文本模型架起视觉桥梁:粘贴图片,输出结构化 JSON 证据(OCR、版面、语义)。
ysr666/dsh-vision-router★ 714
为纯文本 Agent 提供视觉能力:内置免 Key 视觉链 + 像素级视觉工具(看图问答、定位、裁剪、像素对比、取色、OCR、矢量化、抠图、截图);粘贴图片即可用。
Anionex/dsh-vision-toolkit★ 680
让纯文本模型更好地做视觉任务:带意图的图片问答、长截图 OCR、UI 还原等。
jing-hy/picturereader★ 16
给纯文本模型的"读图"能力:图片降分辨率+降色深+结构/色彩指纹渲染成文本网格喂回对话,模型像多模态一样自主缩放、取样、OCR 读图;纯本地零外部模型依赖,附读图方法论 skill 与可选 PaddleOCR。
linenxi-ctrl/dsh-vision★ 12
外挂识图插件:鲸鱼按钮配置面板、图片识图自动回传、模型自主截图识图工具。
Flyvhidbwo/dsh-vision-proxy★ 11
DeepSeek 大脑 + 自动识图:GUI 附加的每张图片自动经 OpenAI 兼容 VLM 转译成文字,再交给纯文本的 DeepSeek 作答——有 key 自动走快速通道(默认 qwen3.7-flash,支持百炼/智谱/OpenRouter 等任意 OpenAI 兼容端点),无 key 自动探测本地 Ollama(零配置,图片不出本机)。