OCR¶
Any number of textual fields can be scanned from the image. By default this happens for vehicle_direction as in this Hikvision example.

Each field can have optional permitted values (Unknown returned if none of them found) and a set of corrections to handle occasional OCR errors, where corrections are simple strings or regular expressions.
Use the OCR Tool for quick tests of configuration with a local image
OCR Stages¶
- Crop the image to a box starting at
xandyposition, measured from the bottom left of the image and a given height and width - Optionally invert the image colours for better capture accuracy
- Run OCR over the cropped image
- Apply optional corrections
- Optionally restrict to a list of values, forcing case if needed
Startup Check¶
When any event uses OCR fields, ANPR2MQTT reads a small bundled sample image at startup, the caption bar from the Hikvision example above, and expects vehicle_direction to be Forward. This checks the Tesseract OCR engine is installed and working, independently of your own field settings, and logs either Verified OCR or an error. The app keeps running either way, but OCR fields will read as Unknown until a failure is fixed.
Outside Docker, a failure usually means the tesseract binary isn't installed or isn't on the PATH. Every event reads the hik_direction field unless told otherwise, so if your images have no text worth reading, turn OCR off for each event with ocr_field_ids: []. That also skips this check. To skip only the check:
Example Configuration¶
The configuration for this can be in the anpr2mqtt.yaml file, or in environment variables or command line arguments.
In this example hik_direction is the ocr_field_id value that can be referenced in an event, and label is the name of the attribute that will appear in the Home Asssitant entity attributes.
ocr:
hik_direction:
label: vehicle_direction
values: Reverse, Forward
invert: true
crop:
x: 0
y: 850
h: 30
w: 650
correction:
Forward:
- F.*wd
Reverse:
- R.*v.*se
- Back.*
Use the debug tools to quickly iterate over an image, for example:
or to test cropping values: