Vision¶
The Vision service recognizes text (OCR) and reads barcodes and QR codes in images, with Apple's Vision framework on the device. Access it via app.vision. It needs no permission.
An image is a path, encoded image bytes (PNG, JPEG, HEIC...), or a CameraFrame from app.camera.
print(app.vision.text("~/Desktop/screenshot.png"))
for code in app.vision.detect_barcodes(app.camera.capture_photo()):
print(code.symbology, code.payload)
Methods¶
recognize_text(image, languages=None, fast=False, correct=True, timeout=60.0)¶
The lines of text in an image, top to bottom, as RecognizedText.
| Parameter | Type | Description |
|---|---|---|
image |
str \| PathLike \| bytes \| CameraFrame |
The image |
languages |
list[str] |
Language codes in order of preference, such as ["it-IT", "en-US"]. Detected automatically by default |
fast |
bool |
Trade accuracy for speed |
correct |
bool |
Apply language correction to the recognized words |
timeout |
float |
Seconds to wait; a large image can take a while |
text(image, **options)¶
The recognized lines joined with newlines. Takes the options of recognize_text.
detect_barcodes(image, symbologies=None, timeout=60.0)¶
The barcodes and QR codes in an image, as Barcode. symbologies restricts the search, such as ["qr", "ean13"].
text_languages(fast=False) and barcode_symbologies()¶
The language codes and the barcode kinds the system supports.
Results¶
RecognizedText |
|
|---|---|
text |
The line |
confidence |
From 0 to 1 |
box |
Where it is |
Barcode |
|
|---|---|
payload |
The decoded content, or None when it is not text |
symbology |
"qr", "ean13", "code128"... |
box |
Where it is |
A Box has x, y, width and height, normalized from 0 to 1 with the origin at the top left: box.x * image_width is the left edge in pixels.