Skip to content

pandaAIGC/win-ocr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Win OCR

Win OCR is a small, local Windows OCR toolkit. It wraps the built-in Windows.Media.Ocr engine with:

  • a tiny .NET CLI (WinOcrCli)
  • a Python package (winocr) for full-image OCR, ROI OCR, batch OCR, and caching

Requirements

  • Windows 10/11
  • .NET 8 SDK or newer
  • Python 3.9+
  • Windows OCR language pack for the language you want to recognize

Install language packs in Windows Settings:

Time & language -> Language & region -> Add a language

Build the OCR CLI

cd dotnet\WinOcrCli
dotnet publish -c Release -r win-x64 --self-contained true

The executable will be created under:

dotnet\WinOcrCli\bin\Release\net8.0\win-x64\WinOcrCli.exe

You can pass that path to Python with --ocr-exe, or copy it to a directory on your PATH.

Install Python Wrapper

python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e .

Usage

OCR a full image:

winocr image.png --ocr-exe dotnet\WinOcrCli\bin\Release\net8.0\win-x64\WinOcrCli.exe

Use a language tag:

winocr image.png --lang zh-CN --ocr-exe path\to\WinOcrCli.exe

OCR a region of interest:

winocr image.png --roi 0,0,1200,300 --ocr-exe path\to\WinOcrCli.exe

Batch OCR all images in a folder:

winocr .\screenshots --glob "*.png" --jsonl output\ocr.jsonl --ocr-exe path\to\WinOcrCli.exe

Use from Python:

from winocr import WinOcrEngine

engine = WinOcrEngine(ocr_exe=r"path\to\WinOcrCli.exe")
text = engine.ocr_image(r"C:\path\to\image.png", lang="en-US")
print(text)

Notes

  • This is local OCR: images are sent only to the Windows OCR runtime.
  • ROI values are x,y,width,height in pixels.
  • OCR results are cached by image hash, ROI, and language in .winocr-cache/.

License

MIT

About

Local Windows.Media.Ocr CLI and Python wrapper

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors