natocr¶
natocr (native ocr) is a small Python wrapper around the OCR engines that already ship with macOS and Windows: the Vision framework on macOS and Windows Runtime OCR on Windows.
These built-in engines are generally faster, more efficient, and more accurate than third-party alternatives like Tesseract. natocr makes reaching for them painless via one clean Python API instead of wrangling with Objective-C bridges or WinRT async plumbing.
Install¶
Add the extras group for JPEG XL / XR / HD and DjVu decoding (see
supported file formats):
Quick start¶
recognize() always returns a list - one OCRResult
per page. Most images are a single page, so reach for pages[0]; see
Multi-page documents for DjVu / TIFF / GIF /
animated PNG / multi-image HEIC/HEIF.
Bounding Boxes¶
page = ocr.recognize("receipt.png")[0]
for element in page.elements:
box = element.bounds.bounds
print(f"{element.text!r} @ {box} conf={element.confidence}")
'Acme Coffee' @ (24.0, 18.0, 180.0, 32.0) conf=0.97
'Latte' @ (24.0, 70.0, 96.0, 28.0) conf=0.95
'$4.50' @ (220.0, 70.0, 80.0, 28.0) conf=0.88
Confidence Scores¶
On macOS you can view the confidence score of the total detections or per individual detection. This is not currently available on windows.
page = ocr.recognize("drivers-license.jpg")[0]
# avg confidence, or None if unavailable
print(f"Overall confidence: {page.confidence}")
Next steps¶
- Usage - confidence scores, bounding boxes, languages, accepted input types, supported file formats, and how to run the tests.
- API Reference - the full
OCR/OCRResult/TextElement/BoundingBoxreference, generated from the source.