Finds and reads the lines of text in an image with PP-OCR models on the
NPU: a DB detector (ch_PP_OCRv3_det at 640 × 480) and a CTC recognizer
(ch_PP_OCRv4_rec at 320 × 48), with the recognizer's dictionary.
{:ok, ocr} =
AxeraNPU.OCR.load("ch_PP_OCRv3_det_npu.axmodel", "ch_PP_OCRv4_rec_npu.axmodel",
"ppocr_keys_v1.txt")
{:ok, lines} = AxeraNPU.OCR.read(ocr, rgb, 960, 540)
Enum.map(lines, & &1.text)
#=> ["NanoKVM-Go offline OCR on the NPU", "离线文字识别:神经网络处理器", ...]Lines are axis-aligned boxes, which suits screens. A line wider than the recognizer's input is read in pieces, cut between letters.
Summary
Functions
Loads the detector and the recognizer onto the NPU, with the recognizer's dictionary (one character per line).
Like load/3, from the files' contents.
The lines of text in an RGB image as an Nx tensor of type {:u, 8} and
shape {height, width, 3}.
The lines of text in an RGB image (width × height × 3 bytes), top to
bottom and left to right.
Types
@type t() :: %AxeraNPU.OCR{ref: reference()}
Functions
Loads the detector and the recognizer onto the NPU, with the recognizer's dictionary (one character per line).
Like load/3, from the files' contents.
@spec read(t(), struct()) :: {:ok, [AxeraNPU.OCR.Line.t()]} | {:error, atom()}
The lines of text in an RGB image as an Nx tensor of type {:u, 8} and
shape {height, width, 3}.
@spec read(t(), binary(), pos_integer(), pos_integer()) :: {:ok, [AxeraNPU.OCR.Line.t()]} | {:error, atom()}
The lines of text in an RGB image (width × height × 3 bytes), top to
bottom and left to right.